Filter löschen
Filter löschen

solve an equation by functions and plot it

1 Ansicht (letzte 30 Tage)
RSHU FA
RSHU FA am 20 Apr. 2018
Kommentiert: RSHU FA am 20 Apr. 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?

Akzeptierte Antwort

Torsten
Torsten am 20 Apr. 2018
Bearbeitet: Torsten am 20 Apr. 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.

Weitere Antworten (0)

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by