Effacer les filtres
Effacer les filtres

solve an equation by functions and plot it

1 vue (au cours des 30 derniers jours)
RSHU FA
RSHU FA le 20 Avr 2018
Commenté : RSHU FA le 20 Avr 2018
It's my first try to write a function. Could anyone please help me? I defined a function such that:
function [zdot]=func2q2(t,z)
global w
b=[0 ; 5*sin(wt)]
A=[0 ,1 ; -100, -1];
zdot=A*z+b;
And I want to drow y for w=2, 6,
global w
t=[0,10];
zt0=[0 0];
[T3,Z3]=ode45(@func2q2, t, zt0);
figure;plot(T3,Z3);grid on
legend('w=2','w=6');
How can I say for any value of w calculate the function and plot?

Réponse acceptée

Torsten
Torsten le 20 Avr 2018
Modifié(e) : Torsten le 20 Avr 2018
tspan=0:0.1:10;
zt0=[0 0];
w = [2 6];
for i=1:numel(w)
  [T,Z_actual] = ode45(@(t,z)func2q2(t,z,w(i)),tspan,zt0);
  Z(:,:,i) = Z_actual(:,:);
end
plot(T,Z(:,1,1),T,Z(:,1,2))
function [zdot]=func2q2(t,z,w)
b=[0 ; 5*sin(w*t)]
A=[0 ,1 ; -100, -1];
zdot=A*z+b;

Best wishes

Torsten.

  1 commentaire
RSHU FA
RSHU FA le 20 Avr 2018
Thanks a lot. I really appreciate that.

Connectez-vous pour commenter.

Plus de réponses (0)

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!

Translated by