如何解高阶时变微分方程?关于ode45的用法~。

ode45 help 文档关于解时变微分方程有如下描述
Example 3
This example solves an ordinary differential equation withtime-dependent terms.
Consider the following ODE, with time-dependent parameters definedonly through the set of data points given in two vectors:
y'(t) + f(t)y(t) = g(t)
Theinitial condition is y(0) = 0, where the function f(t) isdefined through the n-by-1 vectors tf and f,and the function g(t) is defined through the m-by-1 vectors tg and g.
First, define the time-dependent parameters f(t) and g(t) asthe following:
ft = linspace(0,5,25); % Generate t for f
f = ft.^2 - ft - 3; % Generate f(t)
gt = linspace(1,6,25); % Generate t for g
g = 3*sin(gt-0.25); % Generate g(t)
Write a function to interpolate the data sets specifiedabove to obtain the value of the time-dependent terms at the specifiedtime:
function dydt = myode(t,y,ft,f,gt,g)
f = interp1(ft,f,t); % Interpolate the data set (ft,f) at time t
g = interp1(gt,g,t); % Interpolate the data set (gt,g) at time t
dydt = -f.*y + g; % Evalute ODE at time t
Call the derivative function myode.m withinthe MATLAB ode45 function specifying timeas the first input argument :
Tspan = [1 5]; % Solve from t=1 to t=5
IC = 1; % y(t=0) = 1
[T Y] = ode45(@(t,y) myode(t,y,ft,f,gt,g),Tspan,IC); % Solve ODE
Plot the solution y(t) as a functionof time:
plot(T, Y);
title('Plot of y as a function of time');
xlabel('Time'); ylabel('Y(t)');
但是关于高阶方程,比如2阶,必须要引入状态量进行降阶,变成1阶才能用ode45
比如
y''+c(t)y'+my=f(t)
令 x1=y
x2=y'
x3=y''
原微分方程化为
x1'=x2
x2'=-c(t)x2-kx1+f(t)方程组
第二个方程化为1阶段,但是引入了一个x1啊。在使用ode45所述的例子的时候,如何处理?

 采纳的回答

sacobeh
sacobeh 2022-11-25

0 个投票

你这里没有必要引入 x3,只要 x1、x2就够了。也就是原1元2阶微分方程转化为了2元1阶微分方程组:
x1'=x2
x2'=-c(t)x2-kx1+f(t)
对这个微分方程组直接用ode求解,但你需要的只是x1的解(因为 x1 就是 y)。 返回值的第一列对应 x1,也就是你要求的 y,第二列是 x2',可以忽略

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 数值积分和微分方程 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!