Effacer les filtres
Effacer les filtres

solve Fourth Order Difference Equation:X​(n+4)+X(n+​3)-3*X(n+2​)-5*X(n+1)​+2*X(n)=0,​with Initial conditions​:X(0)=1,X(​1)=0,X(2)=​1,X(3)=2

2 vues (au cours des 30 derniers jours)
this is my code,but the figure seems very confused
%Solving homogeneous differential equation characteristic equation solution
syms r
r_sol=solve(r^4+(r^3)-(3*r^2)-(5*r)+2==0,r);
r1=vpa(r_sol(1));%Imaginary solution 1
r2=vpa(r_sol(2));%Imaginary solution 2
r3=vpa(r_sol(3));%Real number solution 1
r4=vpa(r_sol(4));%Real number solution 2
Im=imag(r2);%Get the imaginary part
Im=abs(Im);
Re=real(r2);%Get the real part
FI=sqrt(Im^2+Re^2);
CITA=atan(Im/Re);
A=[FI*cos(CITA) FI*sin(CITA) r3 r4;
(FI^2)*cos(2*CITA) (FI^2)*sin(2*CITA) r3^2 r4^2;
(FI^3)*cos(3*CITA) (FI^3)*sin(3*CITA) r3^3 r4^3;
(FI^4)*cos(4*CITA) (FI^4)*sin(4*CITA) r3^4 r4^4];
B=[1 0 1 2]';
C=A\B;
x=linspace(1,10,10);
Y=C(1,1).*(FI.^x).*cos(x.*CITA)+C(2,1)*(FI.^x).*sin(x.*CITA)+C(3,1).*(r3.^x)+C(4,1).*(r4.^x);
plot(Y);
hold on
X=zeros(10,1);
X(1)=1;X(2)=0;X(3)=1;X(4)=2;
for i=5:1:10
X(i)=-X(i-1)+3*X(i-2)+5*X(i-3)-2*X(i-4);
end
X=X';
plot(X,'*')
  2 commentaires
Nicolas Schmit
Nicolas Schmit le 10 Nov 2017
"the figure seems very confused"
What results are you expecting?
weihongdragon
weihongdragon le 10 Nov 2017
I want to solve the difference equationto get The general solution of the difference equation .and The two lines should be superposition

Connectez-vous pour commenter.

Réponses (1)

Nicolas Schmit
Nicolas Schmit le 10 Nov 2017
Replace
C=A\B;
with
C = double(A)\B;
The symbolic toolbox does not return the expected solution because the matrix A is singular.
  1 commentaire
weihongdragon
weihongdragon le 10 Nov 2017
%Solving homogeneous difference equation characteristic equation solution
syms r
r_sol=solve(r^4+(r^3)-(3*r^2)-(5*r)+2==0,r);
r1=vpa(r_sol(1));%Imaginary solution 1
r2=vpa(r_sol(2));%Imaginary solution 2
r3=vpa(r_sol(3));%Real number solution 1
r4=vpa(r_sol(4));%Real number solution 2
Im=imag(r2);%Get the imaginary part
Im=abs(Im);
Re=real(r2);%Get the real part
FI=sqrt(Im^2+Re^2);
CITA=atan(Im/Re);
A=[FI*cos(CITA) FI*sin(CITA) r3 r4;
(FI^2)*cos(2*CITA) (FI^2)*sin(2*CITA) r3^2 r4^2;
(FI^3)*cos(3*CITA) (FI^3)*sin(3*CITA) r3^3 r4^3;
(FI^4)*cos(4*CITA) (FI^4)*sin(4*CITA) r3^4 r4^4];
B=[1 0 1 2]';
C=double(A)\B;
x=linspace(1,10,10);
Y=C(1,1).*(FI.^x).*cos(x.*CITA)+C(2,1)*(FI.^x).*sin(x.*CITA)+C(3,1).*(r3.^x)+C(4,1).*(r4.^x);
plot(Y);
hold on
X=zeros(10,1);
X(1)=1;X(2)=0;X(3)=1;X(4)=2;
for i=5:1:10
X(i)=-X(i-1)+3*X(i-2)+5*X(i-3)-2*X(i-4);
end
X=X';
plot(X,'*')
I have resubmited my code,and try your method , it still the same. I think the format of general solution is wrong.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by