CAPE Forum
MathWorks => Matlab => Topic started by: kimsel on April 06, 2012, 10:40:50 AM

I want to solve a series of ordinary differential equations (ODE). Both are first order.
Here are the two differential equations:
dx/dt = 5.18(1x)/T >Equation  1
dT/dt = 3.165(1x)+0.4(300T) >Equation  2
I want to solve them using Matlab.
Thank you.

In the Matlab editor write the following code:
function yp = programs(t,y)
xx=y(1);
tt=y(2);
yp1=5.18*(1xx)/tt;
yp2=3.165*(1xx)+0.4*(300tt);
yp=[yp1;yp2];
Save this file as programs.m
Then add it to the path by clicking the run button.
Now to solve the equations type the following code in the workspace window:
[t,y]=ode45(@programs,[0 5], [0,20])
[0 5] is the initial and final value of time (assuming that you are differentiating with respect to time). [0,20] is the initial values of the variables: x and T.
To plot the results, you can use the plot function. Type the following code in the workspace window:
plotyy(t,y(:,1),t,y(:,2));

Now, i am needing to solve equations system:
1.05*x" + 1.155*x' + 133.333*x + 0.043*y" = 0
0.86*x" + y" + 0.254*y' + 161.333*y = 0
With conditions: x(0) = 0.015; x'(0) = 0;
I has used commands as:
>> a = 1.05;
>> b = 1.155;
>> c = 133.333;
>> d = 0.043;
>> e = 0.86;
>> f = 1;
>> g= 0.254;
>> h = 161.333;
>> syms x y t;
>> [x,y] = dsolve('a*D2x + b*Dx + c*x + d*D2y = 0, e*D2x + f*D2y + g*Dy + h*y = 0' , 'x(0) = 0.015,Dx(0)=0' , 't')
but error, i don't know why, i hope that everyone can help me. Thank you so much