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 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Nicolas Schmit
2017-11-10
Replace
C=A\B;
with
C = double(A)\B;
The symbolic toolbox does not return the expected solution because the matrix A is singular.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!