フィルターのクリア

Initial conditions on ODE45 ?

32 ビュー (過去 30 日間)
Robin
Robin 2011 年 7 月 30 日
コメント済み: Pasindu Ranasinghe 2021 年 7 月 22 日
Im trying to solve this IVP: e^y +(t*e^y - sin(y))*(dy/dt)=0 with the initial condition y(2)=1.5.
I was just not sure how to do it with the initial condition with Y(2)=1.5, iknow how to do it if it were y(0)=1.5:
f= @(t,y) (exp(y)+(t.*exp(y)-sin(y))); % This is the function.
[t,y]=ode45(f, [0.5,4], 1.5); % trange is from 0.5 to 4
plot(t,y)
can someone please help me out?

採用された回答

Jan
Jan 2011 年 7 月 30 日
This uses the initial value y(0.5)=1.5 ( not y(0)=1.5):
[t, y] = ode45(f, [0.5, 4], 1.5);
So for y(2)=1.5:
[t, y] = ode45(f, [2, 4], 1.5);
Note: The initial value problem starts at the inital point.
[EDITED]: The call to ODE45 is equivalent, if the problem is formulated in backward direction - an "final value problem": tspan is still [ti, tf], but now ti > tf.
  9 件のコメント
Walter Roberson
Walter Roberson 2017 年 7 月 26 日
Liu Langtian comments to Jan Simon
right
Pasindu Ranasinghe
Pasindu Ranasinghe 2021 年 7 月 22 日
Example Code
Use ode45() to find the approximate values of the solution at t in the range of 1 to 3
function ydot = eqns(t,y)
ydot=(t-exp(-t))/(y+exp(y));
end
###################################
%%Code
[t1,y1]=ode45(@eqns,[1.5 1], 0.5);
hold on;
[t2,y2]=ode45(@eqns,[1.5 3], 0.5);
hold off
t=[t1;t2];
y=[y1;y2];
plot(t,y,'-o')

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

その他の回答 (1 件)

Subha Fernando
Subha Fernando 2011 年 10 月 26 日
let say function is dy/dt = y (t-y).
If initial condition is given at y(1) = 0.5 not at y(0) then we define the RHS as
function output = funcRHS(t, y) output = y *(t-y); end
%then u can call
hold on ode45('funcRHS', [1, -1], 0.5) ode45('funcRHS', [1,5], 0.5)
%Here you can see and read the initial value at y(0) also

カテゴリ

Help Center および File ExchangeProgramming についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by