解决功能离散的ODE系统(matlab) [英] Solving a system of ODEs where the functions are given discrete (matlab)

查看:494
本文介绍了解决功能离散的ODE系统(matlab)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这次我的问题是基于我几个月前问过的一个老问题(请参阅

My question this time is base on an old question I have asked for some months ago (see HERE) If you don't want to go through my first question I can give a short overview about that problem.

在我的第一个问题中,我有两个向量,第一个fx包含函数值:

In my first question I had two vectors, the first one fx containing function values:

fx = [0.5644 0.6473 0.7258 0.7999 0.8697 0.9353 0.9967 1.0540 1.1072 1.1564 ...
      1.2016 1.2429 1.2803 1.3138 1.3435 1.3695 1.3917 1.4102 1.4250 1.4362 ...
      1.4438 1.4477 1.4482 1.4450 1.4384 1.4283 1.4147 1.3977 1.3773 1.3535 ...
      1.3263 1.2957 1.2618 1.2246 1.1841 1.1403 1.0932 1.0429 0.9893 0.9325 0.8725];

第二个x包含评估函数的点:

the second one x containing the points where the function was evaluated:

x = 0:0.25:10

此离散函数fx是一个 ode ,我需要借助matlab的 ode45 对其进行求解.但是 ode45 不采用离散函数,因此解决方案是对这两个向量进行插值.然后,我可以有一个函数句柄,可以发送 ode45 ,如下所示:

This discrete function fx is an ode and I needed to solved it by means of ode45 from matlab. but ode45 doesn't take discrete functions, so the solution was to interpolate these two vectors. Then I could have a function-handle which I could send to ode45, like this:

f = @(xq)interp1(x,fx,xq);
tspan = [0 1];
x0 = 2;
xout = ode45(@(t,x)f(x),tspan,x0);

我现在的问题:

这一次,我没有一个方程代表一个 ode ,我有一个 odes 系统,但是,就像在给函数离散之前一样.这意味着我有:

This time I don't have only one equation representing one ode, I have a system of odes, but, like before the functions are given discrete. This means that I have:

fx1 = [....function values...]
x1 = [...the points where the function fx1 was evaluated...]

fx2 = [....function values...]
x2 = [...the points where the function fx2 was evaluated...]

fx3 = [....function values...]
x3 = [...the points where the function fx3 was evaluated...] 

我需要能够使用 ode45 解决这个颂歌系统.但是我不能简单地同时插值每个方程式并将其发送到ode45,这是错误的.我需要将孔系统发送到ode45.

And I need to be able to solve this system of odes with ode45. But I cannot simply interpolate each equation at the time and send it to ode45, this will be wrong. I need to send the hole system to ode45.

我尝试了不同的方法,但是我的编程技能花了很长时间才能够解决这个问题,这是因为我正在寻求帮助!

I have tried different things, but my programming skill just don't stretch so long that I can solve this problem, this is the reason because I am asking for help!

我的猜测解决方案

我相信,如果使用for-loop仅使一个包含系统3个内插方程的函数句柄,则可以将此一个函数句柄发送给ode45.听起来是个不错的选择吗?

I believe that if I use a for-loop to make only one function handle containing the 3 interpolated equations of the system, I could send this one function-handle to ode45. Does this sounds like a good alternative?

PS:如果需要,我可以很高兴地发布向量fx1,fx2,fx3,x1,x2,x3的值!

PS: I can gladly post the values of the vectors fx1,fx2,fx3,x1,x2,x3 if needed(!)

推荐答案

定义此函数并将其保存在function_helper.m

Define this function and save it in function_helper.m

function result = function_helper(f1, x1, f2, x2, f3, x3, xq)
    result = [
        interp1(x1, f1, xq(1))
        interp1(x2, f2, xq(2))
        interp1(x3, f3, xq(3))
    ];
end

然后像这样整合

f = @(t,xq) function_helper(f1, x1, f2, x2, f3, x3, xq);
tspan = [0 1];
x0 = 1;
xout = ode45(f, tspan, x0);

这篇关于解决功能离散的ODE系统(matlab)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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