# Matlab to solve first order differential equation

• Jun 24th 2008, 10:58 AM
azin.kaf304
Matlab to solve first order differential equation
Hello all,
I am a newbie to Matlab.
I want to solve the first order differential equation.
I have 6 equations.
p10'(t)=p10(t)(-M1+M1(t10+t11)+M1*t11)+P20(t)(M1*t10)+P01(t)(M2*t2 1)+p21(t)(M2*t20)
p20'(t)= .....
.....
.....
....
.....
my teacher told me that at the end of solving , p10+p20+p....+...+..+..=1 and i have to plot that i get "1".
could anyone help me how to write ?
Thanks a lot.
• Jun 24th 2008, 01:57 PM
CaptainBlack
Quote:

Originally Posted by azin.kaf304
Hello all,
I am a newbie to Matlab.
I want to solve the first order differential equation.
I have 6 equations.
p10'(t)=p10(t)(-M1+M1(t10+t11)+M1*t11)+P20(t)(M1*t10)+P01(t)(M2*t2 1)+p21(t)(M2*t20)
p20'(t)= .....
.....
.....
....
.....
my teacher told me that at the end of solving , p10+p20+p....+...+..+..=1 and i have to plot that i get "1".
could anyone help me how to write ?
Thanks a lot.

The way you have expressed this is not clear. In the fragment you give what are variables and what are constants.

RonL
• Jun 25th 2008, 06:07 AM
azin.kaf304

p10'(t)=p10(t)(-M1+M1(t10+t11)+M1*t11)+P20(t)(M1*t10)+P01(t)(M2*t2 1)+p21(t)(M2*t20)

In this equation , constants are M1,M2,t10,t11,t21,t20.
let's say M1=1,M2=2,t10=0.1,t11=0.2,t21=0.1....
and the initial value of p10(t),p20(t),p....... are 1,0,0,0,0,0. Example, p10(t)=1,p20(t)=0,p...

If you something still not clear, i always glad to wirte here since i very need to solve this .
• Jun 25th 2008, 09:05 AM
CaptainBlack
First have you read the help files on the ODE solvers?

Also see here particularly section 8.

RonL
• Jun 26th 2008, 03:02 AM
azin.kaf304
my first function program

xxxxxxxxxxxxxxxxx
function dp = mine(t,p)
M1=1;M2=2;t10=0.1;t11=0.1;t12=0.1;t111=0.1;t112=0. 01;
t122=0.02;t20=0.12;t21=0.11;t22=0.006;t211=0.099;t 212=0.11;t222=0.125;
dp = zeros(6,1); % a column vector
%dp(1)=P10
dp(1)=(p(1)*(-M1+(M1*(t10+t11))+(M1*t11)))+(p(3)*(M1*t10))+(p(4) *(M2*t21))+(p(5)*(M2*t20));
%dp(2)=P1,0+1
dp(2)=(p(2)*(-M1+(M1*t11)+(M1*(t111+t11))+(M1*(t112+t11))+(M1*(t 122+t11))))+(p(1)*(M1*t112))+(p(3)*(M1*t12))+(p(4) *(M2*t212));
%dp(3)=P1+1,0
dp(3)=(p(3)*(-M1+(M1*t11)+(M1*(t111+t11))+(M1*(t112+t11))+(M1*(t 122+t11))))+(p(1)*(M1*t111))+(p(4)*(M2*t22))+(p(5) *(M2*t21));
%dp(4)=P01
dp(4)=(p(4)*(-M2+(M2*(t20+t22))+(M2*t22)))+(p(1)*(M1*t12))+(p(2) *(M1*t10))+(p(6)*(M2*t20));
%dp(5)=P0+1,1
dp(5)=(p(5)*(-M2+(M2*t22)+(M2*(t211+t22))+(M2*(t212+t22))+(M2*(t 222+t22))))+(p(1)*(M1*t122))+(p(6)*(M2*t21));
%dp(6)=P0,1+1
dp(6)=(p(6)*(-M2+(M2*t22)+(M2*(t211+t22))+(M2*(t212+t22))+(M2*(t 222+t22))))+(p(2)*(M1*t12))+(p(4)*(M2*t222));
%dp = dp(:) ;
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxx

Main program

t0=0;
tf=10;
x0 = [1 0 0 0 0 0]
[X,Y]=ode45(@mine,[t0,tf],x0);
%plot(T,P(:,1),'-',T,P(:,2),'-',T,P(:,3),'-',T,P(:,4),'-',T,P(:,5),'-',T,P(:,6),'-')
plot(X,Y)

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxx

I want to know the value of p10,p01,1+1,0,..... 6 variables.
and I want to get p10+p01+..+..+..+..=1.
so i can prove with plot about we get 1 for sum of 6 variables.