ODE45 help varying values

4 ビュー (過去 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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by