Matlab:是否可以用数字方法求解混合了初始条件和最终条件的ode系统? [英] Matlab: Is it possible to numerically solve a system of ode's with a mixture of initial and terminal conditions?

查看:68
本文介绍了Matlab:是否可以用数字方法求解混合了初始条件和最终条件的ode系统?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 ode45 解决ODE系统:

  [X,Y] = ode45(@sys,[0,T],y0); 

哪里

 函数dy = sys(t,y)dy(1)= f_1(y)dy(2)= f_2(y)dy(3)= f_3(y)结尾 

问题在于函数 ode45 要求 y0 为初始值 [y_1(0),y_2(0),y_3(0)] ,而在我的系统中,我只有可用的 [y_2(0),y_3(0),y_3(T)] 值.

从数学上讲,这组初始/终止条件应该足以固定系统,但是我可以通过 ode45 或MATLAB中的任何其他函数来使用它吗?

谢谢!

解决方案

在Matlab文档中进行了一些挖掘之后,我认为更优雅的方法是使用 bvp4c 函数. bvp4c 是专门设计用于处理这样的边值问题的功能,与 ode ** 相反,后者实际上仅用于初始值问题.实际上,在Matlab中还有一整套其他功能,例如 deval bvpinit ,它们确实促进了 bvp4c 的使用.这是与Matlab文档的会很有帮助的.

I'm trying to use ode45 to solve a system of ODE's:

[X,Y]=  ode45(@sys,[0, T],y0);

where,

function dy = sys(t,y)

        dy(1) = f_1(y)
        dy(2) = f_2(y)
        dy(3) = f_3(y)
end

The problem is that the function ode45 requires that y0 be initial values [y_1(0), y_2(0), y_3(0)], while in my system, I only have the values [y_2(0), y_3(0), y_3(T)] available.

Mathematically, this set of initial/terminal conditions should be enough to pin down the system, but is there any way I can work with that by ode45 or any other functions in MATLAB?

Thanks!

解决方案

After digging in the Matlab documentation for a little bit, I think the more elegant way is to use the bvp4c function. bvp4c is a function specifically designed to handle boundary value problems like this, as opposed to ode**, which are really for initial value problems only. In fact, there's a whole set of other functions such as deval and bvpinit in Matlab that really facilitate the use of bvp4c. Here's the link to the Matlab documentation.

I'll post a brief (and perhaps a bit contrived) example here:

function [y1, y2, y3] = test(start,T)

solinit = bvpinit(linspace(0,3,10), [1,1,0]);
sol = bvp4c(@odefun,@bvpbc,solinit);

tspan = linspace(start,T,100);
S = deval(sol, tspan);
y1 = S(1,:);
y2 = S(2,:);
y3 = S(3,:);

plot (tspan,y1)

figure
plot (tspan,y2)

figure
plot (tspan,y3)


%% system definition & BVCs

function dydx = odefun(t,y)
    dydx(1) = y(1) + y(2) + t;

    dydx(2) = 2*y(1) + y(2);

    dydx(3) = 3 * y(1) - y(2);
end

function res = bvpbc(y0,yT)
   res= [y0(3) yT(2) yT(3)];
end

end

The test function outputs 3 vectors of solutions points for y1, y2 and y3 respectively, and also plots them.

Here are the variable paths plotted by Matlab:

Also, I found this video by professor Jake Blanchard from WMU to be very helpful.

这篇关于Matlab:是否可以用数字方法求解混合了初始条件和最终条件的ode系统?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆