Need to do ode45 for various values iteratively

조회 수: 1 (최근 30일)
Muhammad Usman
Muhammad Usman 2014년 7월 21일
편집: Mischa Kim 2014년 7월 21일
Hi i am writing a code for ode45 for which i have to variate the value of "aplha",after each time the ode45 evaluates and the use the next value. Say i have to use alpha=10:15
function xp=check(t,x)
xp=zeros(2,1);
xp(1)=x(2);
xp(2)=alpha*x(2)-x(1);
end
running in another m-file
[T,Y]=ode45(@check,[0 0.28],[0.087 0]);
plot(T,Y(:,1),'-o')
grid on;
i need the plot of all in the iteration in a same plot,please help me Thanks

채택된 답변

Mischa Kim
Mischa Kim 2014년 7월 21일
편집: Mischa Kim 2014년 7월 21일
Muahmmad, you are almost there. Use a loop and something like
function myode()
alpha = 10:15;
figure
hold all
for ii = 1:numel(alpha)
[T,Y] = ode45(@check,[0 0.28],[0.087 0],[],alpha(ii));
plot(T,Y(:,1),'-o')
end
hold off
grid on;
end
function xp = check(t,x,alpha)
xp = zeros(2,1);
xp(1) = x(2);
xp(2) = alpha*x(2) - x(1);
end

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by