Systems of Differential Equations with initial-value problems

168 views Asked by At

I have a problem with some differential equations of first-order. I'm trying to solve them with ode23 and ode23s. The differential equations are:

y’ – z – u = 0

z’ – u – y = 0

u’ – y – z = 0

with the initial values: y(0) = –1, z(0) = 1, u(0) = 0.

I also want to compare it with the ANALYTICAL solution:

y = – exp(x)

z = exp(x)

u = 0

I want to do it this way because I need to do the comparison in order to choose the better solver: ode23 or ode23s, whichever one is closer to the analytical solution.

My code is:

%y'=z+u
%z'=u+y
%u'=y+z
%y(0)=-1,z(0)=1, u(0)=0 inital values 
%y=y(0) z=y(1) u=y(2)

function dy = part1(t,k)

y=k(1);

z=k(2);

u=k(3);

dy=[z+u;u+y;y+z];

and:

%comparıson of  numerıcal and analytıcal equatıons 
%Fırst comparıson functıon

[t1,y1]=ode23('part1',[0 16],[0 1 -1]);

%Second comparıson functıon

[t2,y2]=ode23s('part1',[0 16],[0 1 -1]);

%ya,za,ua are analytıcal equtıons 

ya =(-exp(t1));

za=exp(t1);

ua=0;

%ı have to plot ya,ua and za depends on ode23 and ode23s
%then ı wıll decıde the best solutıon depends on my shape
%either ode23 or ode23s ıs the best?

plot(t1,ya,t1,za,t1,ua);title('ya,za,ua')

figure

plot(t1,y1(:,1),t1,y1(:,2),t1,y1(:,3));title('ode23')

figure

plot(t2,y2(:,1),t2,y2(:,2),t2,y2(:,3));title('ode23s')

But it doesn't work. Could someone help me?

0

There are 0 answers