首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >ode45的初始条件?

ode45的初始条件?
EN

Stack Overflow用户
提问于 2019-03-14 11:55:57
回答 1查看 360关注 0票数 0

我需要使用ode45在t=1、1.5和3处找到解决方案的近似值,然后在0.5、4上绘制解决方案

代码语言:javascript
复制
    %% 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的近似值。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-03-14 13:31:19

由于y(2) = 1.5表示在t=2处,y= 1.5,因此您可以首先使用ode45从下面的代码中获得t=2到t=4的答案。

代码语言:javascript
复制
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之前的值。如下所示。

代码语言:javascript
复制
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)的值。剩下的就是绘图了。您可以使用以下代码来绘制

代码语言:javascript
复制
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");
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55154737

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档