Matlab 版 (精华区)
发信人: candle ( 马 走 日), 信区: Matlab
标 题: How do I reduce the order of ordinary differentia
发信站: 紫 丁 香 (Fri Dec 24 17:40:09 1999), 转信
This is an example of how to reduce a second order differential
equation into two first order equations for use with ode23 or
ode45. The following system of equations consists of one first and
one second order differential equation:
x' = -y * exp(-t/5) + y' * exp(-t/5) + 1 (1)
y''= -2*sin(t) (2)
The first step is to introduce a new variable that equals the first
derivative of the free variable in the second order equation:
z = y' (3)
Taking the derivative of each side yields:
z' = y'' (4)
Substituting (4) into (2) produces the following:
z' = -2*sin(t) (5)
Combining (1), (3), and (5) yields three first order differential
equations.
x' = -y * exp(-t/5) + y' * exp(-t/5) + 1 (1)
z = y' (3)
z' = -2*sin(t) (5)
Since z = y', substitute z in for y' in equation (1). Also, since
MATLAB requires that all derivatives be on the left-hand side,
rewrite equation (3). This produces the following set of equations:
x' = -y * exp(-t/5) + z * exp(-t/5) + 1 (1)
y' = z (6)
z' = -2*sin(t) (5)
To evaluate this system of equations using ode23/ode45, create a
function which contains these differential equations. The function
requires two inputs, the states and time, and returns the state
derivatives. Below is the function named odetest.m:
function xprime = odetest(t,x)
% Since the states are passed in as a single vector, let
%
% x(1) = x
% x(2) = y
% x(3) = z
xprime(1) = -x(2) * exp(-t/5) + x(3) * exp(-t/5) + 1;
xprime(2) = x(3);
xprime(3) = -2*sin(t);
To evaluate the system of equations using ode23, (the same
applies for ode45), define the start and stop times and the initial
conditions of the state vector. For example:
t0 = 5; % Start time
tf = 20; % Stop time
x0 = [1 -1 3] % Initial conditions
[t,x] = ode23('odetest',t0,tf,x0);
--
---------------------------------------------------
I BELIEVE I CAN FLY. I BELIEVE I CAN TOUCH THE SKY.
------------------- CANDLE --------------------
※ 来源:.紫 丁 香 bbs.hit.edu.cn.[FROM: 150.59.34.186]
Powered by KBS BBS 2.0 (http://dev.kcn.cn)
页面执行时间:3.227毫秒