solve an equation by functions and plot it

1 visualización (últimos 30 días)
RSHU FA
RSHU FA el 20 de Abr. de 2018
Comentada: RSHU FA el 20 de Abr. de 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?

Respuesta aceptada

Torsten
Torsten el 20 de Abr. de 2018
Editada: Torsten el 20 de Abr. de 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.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by