Matlab ode23

Solo disponible en BuenasTareas
  • Páginas : 2 (480 palabras )
  • Descarga(s) : 0
  • Publicado : 30 de enero de 2011
Leer documento completo
Vista previa del texto
MATLAB Examples on the use of ode23 and ode45:

Example 1: Use ode23 and ode45 to solve the initial value problem for a first order differential equation:
First create a MatLab functionand name it fun1.m.
function f=fun1(t,y)
Now use MatLab functions ode23 and ode45 to solve the initial value problem numerically and then plot thenumerical solutions y, respectively. In the MatLab window, type in the following commands line by line.
>> [tv1 f1]=ode23('fun1',[0 5],1);
>> [tv2 f2]=ode45('fun1',[0 5],1);>> plot(tv1,f1,'-.',tv2,f2,'--')
>> title('y''=-ty/sqrt(2-y^2), y(0)=1, t in [0, 5]')
>> grid
>> axis([0 5 0 1])

The numerical solutions f1and f2 respectively generated by ode23 and ode45 are almost the same for this example.


Example 2: Use ode23 to solve the initial value problem for a system of first orderdifferential equations:
y1(0)=1, y2(0)=-1, y3(0)=0
t in [0,pi/2].
First, create an M-file which evaluates theright-hand side of the system F(t,Y) for any given t, y1, y2, and y3 and name it funsys.m:
function Fv=funsys(t,Y);
Now type in the following commands in MatLab window line by line:
>> [tv,Yv]=ode23('funsys',[0 pi/2],[1;-1;0]);
>> hold
>> grid
>> title('Example 2')
>> text(0.3,14,'-+- y_1')
>> text(0.3,10,'-x- y_2')
>> text(0.3,-12,'-o- y_3')
>> xlabel('time')
>>hold off
A graph of y1, y2 and y3 is given below:

Note: try using ode45 and compare your results with those obtained by ode23.
Example 3:

(Here, we will use m-files for...
tracking img