如何解高阶时变微分方程?关于ode45的用法~。
Mostra commenti meno recenti
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所述的例子的时候,如何处理?
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su 数值积分和微分方程 in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!