ode45 Error not working

17 ビュー (過去 30 日間)
Bob
Bob 2016 年 7 月 28 日
コメント済み: Torsten 2016 年 7 月 29 日
Use ode45 to overlay plots of solutions to this differential equation with y (0) = c for c ranging from 0 to 1 in steps of 0:1.
equation: 5*y*(1-y)-(1+(1/2)*sin(2*pi*t));
Attempted code:
syms y(t);
for c = 0:0.1:1
f = @(t, y) 5*y*(1-y)-(1+(1/2)*sin(2*pi*t));
[t,y] = ode45(f, [0,0], c)
end
Error:
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in Project_3 (line 33)
[t,y] = ode45(f, [0,0], c);
If I change the 2nd 0 to 1 in the ode45 it works but my question asks for it at y(0).
  1 件のコメント
Torsten
Torsten 2016 年 7 月 29 日
If you set
tspan=[0,0]
as you do, you try to integrate from tstart=0 to tend=0 which does not make sense.
Best wishes
Torsten.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2016 年 7 月 28 日
Do not use for to calculate at those time steps. You cannot use the ode* functions to calculate a single individual time step. Instead, create a vector holding the timesteps you want to be evaluated at and pass that vector in the tspan argument position to ode45 -- a single call, not a loop.

その他の回答 (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