ode45 的初始条件?
Initial Condition for ode45?
我需要使用 ode45 在 t=1、1.5 和 3 处找到解的近似值,然后在 [0.5,4]
上绘制解
%% 7) exp(y)+(t*(exp(y)-sin(y))*y'=0, y(2)=1.5
% 7a) Find approximate values of the solution at t=1, 1.5, and 3 then plot
% the solution on [0.5,4].
[t,y]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),0.5:.2:4,1.5)
如上所示,初始条件从t = 2开始,而不是0。如何使用初始条件从t = 2开始的ode45?我还必须找到低于 t=2 的近似值。
由于 y(2) = 1.5 表示在 t=2,y = 1.5,您可以先使用 ode45 从下面的代码中获取从 t = 2 到 t = 4 的答案。
tspan1 = [ 2 : 0.05 : 4];
[t1,y1]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),tspan1,1.5);
%% Index of t(3) is ((3/0.05) -1 )
y_when_t_3 = y1(((3/0.05) -1 ))
然后你可以使用函数向后获取2之前的值。如下所示。
tspan2 = [ 2 : -0.05 : 0.5];
[t2,y2]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),tspan2,1.5);
y_when_t_1 = y2(length(tspan2)-((1/0.05) -1 ))
y_when_t_1_5 = y2(length(tspan2)-((1.5/0.05) -1 ))
现在您有了 t(1)、t(1.5) 和 t(3) 的值。剩下的就是剧情了。您可以使用以下代码绘制
t1 = t1';
t2 = t2';
y1 = y1';
y2 = y2';
t_plot = [fliplr(t2),t1(2:end)];
y_plit = [fliplr(y2),y1(2:end)];
plot(t_plot,y_plot);
xlabel("t");
ylabel("y");
我需要使用 ode45 在 t=1、1.5 和 3 处找到解的近似值,然后在 [0.5,4]
上绘制解 %% 7) exp(y)+(t*(exp(y)-sin(y))*y'=0, y(2)=1.5
% 7a) Find approximate values of the solution at t=1, 1.5, and 3 then plot
% the solution on [0.5,4].
[t,y]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),0.5:.2:4,1.5)
如上所示,初始条件从t = 2开始,而不是0。如何使用初始条件从t = 2开始的ode45?我还必须找到低于 t=2 的近似值。
由于 y(2) = 1.5 表示在 t=2,y = 1.5,您可以先使用 ode45 从下面的代码中获取从 t = 2 到 t = 4 的答案。
tspan1 = [ 2 : 0.05 : 4];
[t1,y1]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),tspan1,1.5);
%% Index of t(3) is ((3/0.05) -1 )
y_when_t_3 = y1(((3/0.05) -1 ))
然后你可以使用函数向后获取2之前的值。如下所示。
tspan2 = [ 2 : -0.05 : 0.5];
[t2,y2]=ode45(@(t,y) -exp(y)./(t.*(exp(y))-sin(y)),tspan2,1.5);
y_when_t_1 = y2(length(tspan2)-((1/0.05) -1 ))
y_when_t_1_5 = y2(length(tspan2)-((1.5/0.05) -1 ))
现在您有了 t(1)、t(1.5) 和 t(3) 的值。剩下的就是剧情了。您可以使用以下代码绘制
t1 = t1';
t2 = t2';
y1 = y1';
y2 = y2';
t_plot = [fliplr(t2),t1(2:end)];
y_plit = [fliplr(y2),y1(2:end)];
plot(t_plot,y_plot);
xlabel("t");
ylabel("y");