Author Topic: How do I solve two Ordinary Differential equations using Matlab  (Read 18112 times)

Offline kimsel

  • Newbie
  • *
  • Posts: 3
  • Reputation: +1/-0
  • Searching for solution
    • View Profile
Advertisement
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(1-x)/T                       -->Equation - 1

dT/dt = 3.165(1-x)+0.4(300-T)     -->Equation - 2

I want to solve them using Matlab.

Thank you.

Offline pitney1

  • Jr. Member
  • **
  • Posts: 65
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How do I solve two Ordinary Differential equations using Matlab
« Reply #1 on: April 06, 2012, 10:51:07 AM »
In the Matlab editor write the following code:

Code: [Select]
function yp = programs(t,y)

xx=y(1);
tt=y(2);


yp1=5.18*(1-xx)/tt;
yp2=3.165*(1-xx)+0.4*(300-tt);


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));

Offline vuminhky

  • Newbie
  • *
  • Posts: 1
  • Reputation: +0/-0
  • Searching for solution
    • View Profile
Re: How do I solve two Ordinary Differential equations using Matlab
« Reply #2 on: June 07, 2012, 02:45:03 AM »
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
Vuminhky