Ode23 is not outputting solutions at the times I specified between t0 and tf in tspan=[t0, t1, t2..., tf]
1 回表示 (過去 30 日間)
古いコメントを表示
I am using ode23() to solve an ODE between t=0 and t=7, and I want solutions at every 0.1 seconds. I am calling ode23 with tspan=[0, 0.1, 0.2, ..., 7] (which is 71 entries long) but the output solution is only 38 entries long at the times chosen by the solver. It is exactly the same as when tspan=[0 7]. Why is not listening to the argument I gave?
% define ODE
function dydt = myfun(t, y, c, m, g)
v = sqrt(y(2)^2+y(4)^2);
dydt = [y(2); -c*v*y(2)/m; y(4); -c*v*y(4)/m-g];
end
% Simulate ODE
c = 0.028;
m = 0.3;
g = 9.81;
y0 = [0; 35*cosd(65); 0; 35*sind(65)];
times = [0:0.1:7];
soln = ode23(@(t, y) myfun(t, y, c, m, g), times, y0);
xc = soln.y(1, :)';
yc = soln.y(3, :)';
figure
plot(xc, yc)
0 件のコメント
採用された回答
Torsten
2024 年 9 月 14 日
編集済み: Torsten
2024 年 9 月 14 日
If you use the "soln" structure as result, ode23 only respects start and end point from your tspan vector.
After the integrator has finished, you would have to use "deval" to interpolate the solution to the time points of your choice.
I suggest using the [T,Y] solution structure instead:
% Simulate ODE
c = 0.028;
m = 0.3;
g = 9.81;
y0 = [0; 35*cosd(65); 0; 35*sind(65)];
times = [0:0.1:7];
[T,Y] = ode23(@(t, y) myfun(t, y, c, m, g), times, y0);
xc = Y(:,1);
yc = Y(:,3);
figure
plot(xc, yc)
% define ODE
function dydt = myfun(t, y, c, m, g)
v = sqrt(y(2)^2+y(4)^2);
dydt = [y(2); -c*v*y(2)/m; y(4); -c*v*y(4)/m-g];
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!