How to plot a vector map for a differential system(in ode45) with a switch condition ?
4 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
% y is output from ode45
[gridx1,gridy1]=meshgrid(logspace(thetamin,thetamax,length(y(1:fix(end/2),1))),logspace(thetadotmin,thetadotmax,length(thetadot(1:fix(end/2),2))));
quiver(y(1:fix(end/2),1), y(1:fix(end/2),2),gridx1,gridy1);%Only plotted the first half of the output to avoid the even higher frequency areas and used logspace in place of linspace to avoid hanging my laptop
I wish to plot a vector map for a switching system along the switching surface h. So far, I tried quiver, which just hangs my laptop when the high frequency switching condition occurs.
Example problem: ![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031700/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1031685/image.png)
2 commentaires
Réponses (1)
Sam Chak
le 14 Juin 2022
Modifié(e) : Sam Chak
le 14 Juin 2022
Since you didn't provide the code, the following involves some guesswork in an attempt to reproduce/duplicate your graph.
The simplest form of
is probably a additive function, and so I've tried
. But, your scale at
is relatively small.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032065/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032070/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032075/image.png)
k = 0;
fv1 = @(t, x, y) y;
fv2 = @(t, x, y) k*sin(t) + 5.2*sign(-((4/10)*x + y));
opt = odeset('RelTol', 1e-4, 'AbsTol', 1e-6);
[t, v] = ode45(@(t, x) ([fv1(t, x(1), x(2)); fv2(t, x(1), x(2))]), [0 20], [10 0], opt);
Next is plotting.
subplot(2,1,1)
plot(t, v(:,1), 'linewidth', 1.5)
subplot(2,1,2)
plot(v(:,1), v(:,2), 'linewidth', 1.5)
hold on
And then the quiver plot is added.
[X, Y] = meshgrid(0:10/14:10, -4:4/7:0); % Do NOT make very fine mesh partitions
U = Y;
V = 5.2*sign(-((4/10)*X + Y));
quiver(X, Y, U, V, 0.5)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032080/image.png)
I'll let the Experts to handle your case for
, which indicates an non-autonomous system. Probably require quiver3() to show the evolution of the direction field in 3D as the system response is propagated forward in time t, as demonstrated by Dr. @Star Strider in this solution:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1032085/image.png)
Voir également
Catégories
En savoir plus sur 2-D and 3-D Plots dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!