how can i fix a double precision error "DOUBLE cannot convert the input expression into a double array." preciasly the error is at the calculation of a 4x4 matrix named T inside the second for loop

clc clear all
syms mh Lp M M1 Ip It It0 Ie kde kdt kdp Lp LH LM g s x y A=[0 1 0 0 0 0; -(mh*g*Lp)/Ip -kdp/Ip 0 0 0 0; 0 0 0 1 0 0; 0 0 -M/Ie -kde/Ie 0 0 ; 0 0 0 0 0 1; -M/It 0 0 0 0 -kdt/It]; B=[0 0; 0 LH/Ip; 0 0; LM/Ie 0; 0 0; 0 0]; C=[0 0 1 0 0 0; 0 0 0 0 1 0]; D=[0,0;0,0]; C * inv(s * eye(6) - A) * B C1=C(1,:) % first line of OUTPUT C C2=C(2,:) % second line of OUTPUT C T=[0 0; 0 0] T1=T(1,:) T2=T(2,:) n=sym(zeros(1,1)) for j=1:2 primefound=0 for i=1:5 if T(j,:)==0 & primefound==0 T(j,:)=C(j,:)*A^n(j,:)*B n(j,:)=n(j,1)+1 if primefound~=0 return end end end if primefound~=0 end d(j,:)=n(j,:)-1 end disp(T)

1 Comment

please format your code properly by selecting the whole code and by pressing the code button

Sign in to comment.

Answers (1)

I created ‘n’ as a scalar, not a vector. Also, ‘T’ is (2x2) as you created it here.
This version of your code runs (for me) without error:
syms mh Lp M M1 Ip It It0 Ie kde kdt kdp Lp LH LM g s x y
A=sym([0 1 0 0 0 0; -(mh*g*Lp)/Ip -kdp/Ip 0 0 0 0; 0 0 0 1 0 0; 0 0 -M/Ie -kde/Ie 0 0 ; 0 0 0 0 0 1; -M/It 0 0 0 0 -kdt/It]);
B=sym([0 0; 0 LH/Ip; 0 0; LM/Ie 0; 0 0; 0 0]);
C=sym([0 0 1 0 0 0; 0 0 0 0 1 0]);
D=sym([0,0;0,0]);
C * inv(s * eye(6) - A) * B
C1=C(1,:); % first line of OUTPUT C
C2=C(2,:); % second line of OUTPUT C
T=sym([0 0; 0 0]);
T1=T(1,:);
T2=T(2,:);
n=sym(0);
for j=1:2
primefound=0
for i=1:5
if T(j,:)==0 & primefound==0
T(j,:)=C(j,:)*A^n*B
n=n+1
if primefound~=0
return
end
end
end
if primefound~=0
end
d(j)=n-1
end
disp(T)
You will have to change your code to create ‘T’ to be (4x4), and make any other necessary corrections to get the result you want.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 28 Oct 2018

Answered:

on 28 Oct 2018

Community Treasure Hunt

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

Start Hunting!