loop inside ode45 solver

조회 수: 13 (최근 30일)
Fayeza Fayeza
Fayeza Fayeza 2017년 10월 24일
댓글: Fayeza Fayeza 2017년 10월 27일
Hello, I am using loop inside ode45 solver with shooting method ,and want to store data from each iteration. My code only save the last iteration. Please help.
function F=solver(x)
m=-2:1:-1;
u1=zeros(length(m));
for k=1:length(m);
[t{k},u{k}]=ode45(@(t,u)equation(t,u,m(k)),[0 10],init1,options);
s=length(t{k});
F=[u{k}(s,2)-1,u{k}(s,4)];
u1(k)=u{k}(1,3);
end
end
for k=1:length(m);
Final=[m(k),u1(k)]
end
  댓글 수: 1
Fayeza Fayeza
Fayeza Fayeza 2017년 10월 27일
I am still wondering why this loop saved only the last iteration? or I should call ode45 solver many times? but this is useless if there are many values for a parameter m. Please help!

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

답변 (1개)

KSSV
KSSV 2017년 10월 24일
편집: KSSV 2017년 10월 24일
function F=solver(x)
m=-2:1:-1;
u1=zeros(length(m));
S = cell(length(m),1) ;
for k=1:length(m);
[t,u]=ode45(@(t,u)equation(t,u,m(k)),[0 10],init1,options);
S{k} = u(:,3) ;
s=length(t{k});
F=[u{k}(s,2)-1,u{k}(s,4)];
u1(k)=u{k}(1,3);
end
end
for k=1:length(m);
Final=[m(k),u1(k)]
end
  댓글 수: 3
KSSV
KSSV 2017년 10월 24일
Edited..is that you are looking for?
Fayeza Fayeza
Fayeza Fayeza 2017년 10월 24일
yes. After calling ode45 solver I got u with 5 columns u(n,5) with n=1 to 10. I want to edit only u(1,3) for different parameters m. Because of that I am using k loop.

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

카테고리

Help CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by