필터 지우기
필터 지우기

solve an equation by functions and plot it

조회 수: 1 (최근 30일)
RSHU FA
RSHU FA 2018년 4월 20일
댓글: RSHU FA 2018년 4월 20일
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.

  댓글 수: 1
RSHU FA
RSHU FA 2018년 4월 20일
Thanks a lot. I really appreciate that.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by