solve an equation by functions and plot it

1 次查看(过去 30 天)
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?

采纳的回答

Torsten
Torsten 2018-4-20
编辑:Torsten 2018-4-20
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Legend 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by