Effacer les filtres
Effacer les filtres

Loop an if with different parameters

1 vue (au cours des 30 derniers jours)
Brilliant Purnawan
Brilliant Purnawan le 15 Nov 2020
Hi, doing some practice codings and ran into a snag. So, i'm trying to plot(t,y) with different matrix 'e' values? Let's say my first 'e' would be [-1; -2; -3; -4], and second [-2; -3; -4; -5] and keeps increasing with increments of 1 until a maximum value of [-7; -8; -9; -10], and plot everything in the same graph? How would I go about this? Code is below
e = [-1; -2; -3; -4]
K = place(A,B,e);
tspan = 0:0.01:200;
if(c==-1)
y0=[0; 0; 0; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[4; 0; 0; 0])),tspan,y0);
elseif(c==1)
y0=[-3; 0; pi+.1; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[1; 0; pi; 0])),tspan,y0);
else
end
plot(t,y);

Réponse acceptée

Setsuna Yuuki.
Setsuna Yuuki. le 15 Nov 2020
You can use for to graph more than once.
for n=1:7
e = -n:-1:-n-3 % e values [-1 -2 -3 -4]
e = e'; %[-1;-2;-3;-4]
%Your code....
if(c==-1)
y0=[0; 0; 0; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[4; 0; 0; 0])),tspan,y0);
elseif(c==1)
y0=[-3; 0; pi+.1; 0];
[t,y] = ode45(@(t,y)Equation(y,m,M,l,g,b,-K*(y-[1; 0; pi; 0])),tspan,y0);
else
end
% Your code end
plot(t,y); hold on;
end

Plus de réponses (0)

Catégories

En savoir plus sur Graphics Performance dans Help Center et File Exchange

Produits

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by