Vous êtes sur la page 1sur 1

clear;clc;

syms Dx Dy x y x1 x2 y1 y2
f1=Dx+Dy+x-y-3
f2=Dx-Dy-x-y+3
[x,y]=dsolve(f1,f2)
C=symvar([x,y])
x=subs(x,C,{1,1})
y=subs(y,C,{1,1})
to=0;tf=10;
xo=subs(x,'t',to)
xf=subs(x,'t',tf)
yo=subs(y,'t',to)
yf=subs(y,'t',tf)
hold on
fplot(char(x),[to tf])
fplot(char(y),[to tf],'r')
h=0.1
t=to:h:tf
n=length(t)
x=sym('X',[1 n])
y=sym('Y',[1 n])
x=subs(x,{x(1,1),x(1,n)},{xo,xf})
x=vpa(x)
y=subs(y,{y(1,1),y(1,n)},{yo,yf})
y=vpa(y)
ny=length(symvar(y))
%Dy=(y(i+1)-y(i))/h
%Dx=(x(i+1)-x(i))/h
Dy=(y2-y1)/h
Dx=(x2-x1)/h
f3=subs(f1,{'Dx','Dy'},{Dx,Dy})
f4=subs(f2,{'Dx','Dy'},{Dx,Dy})
v1=symvar(f3)
v2=symvar(f4)
for i=1:ny
f5(i,1)=subs(f3,v1,{x(i),x(i),x(i+1),y(i),y(i),y(i+1)})
f6(i,1)=subs(f4,v2,{x(i),x(i),x(i+1),y(i),y(i),y(i+1)})
end
T=symvar([f5,f6])
R=solve(f5,f6)
Rs=cell2num(struct2cell(R))
for i=1:ny
x(1,i+1)=Rs(i)
y(1,i+1)=Rs(ny+i)
end
plot(t,x,'--')
plot(t,y,'--r')