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!