ODE45 help varying values

조회 수: 3 (최근 30일)
john doe
john doe 2018년 4월 7일
답변: Razvan Carbunescu 2018년 4월 9일
So I have a function and I am trying to solve it via ODE45. It works perfectly and gives me my solution and plots it on a nice little graph. What I am struggling to understand is that when I change my parameter value, a different amount of Y values are produced. For example, my code is as follows;
z=0;
f = [1 2 3]
ft =[1 2 3];
g = [4 5 6];
gt = [1 2 3];
Time = [0 30];
IC = 2.5;
for a = [1:3]
for b = [1:3]
Q = [a b];
[t,y] = ode45(@(t,y) Test(t,y,Q,ft,f,gt,g), Time, IC);
end
y=y'
z=z+1;
out(z,:) = [a b y]
end
with an ODE file;
function dydt = Test(t,y,Q,ft,f,gt,g)
f = interp1(ft, f, t,'linear', 'extrap');
g = interp1(gt, g, t, 'linear', 'extrap');
dydt = Q(1)*f+Q(2)*g*y;
end
Now if for example I let a=1 and b=1, then I get 1845 Y values. If however I set a=1 and b=2 then I get 2427 Y values. I really do not understand how simply changing the parameter gives a different 'amount' of solutions. It is making it very difficult to store my solutions in a matrix since I keep getting an error about them not matching up.

채택된 답변

Razvan Carbunescu
Razvan Carbunescu 2018년 4월 9일
The height of the answer is the number of timesteps needed to compute the solution. The a=1, b=2 solution takes more steps to compute to the same T=30 time.
One way to make them match up is to interpolate the solution [t,y] to a common time interval
[t1,y1] = ode45(...)
[t2,y2] = ode45(...)
y2i = interp1(t2,y2,t1);

추가 답변 (0개)

카테고리

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