Info

この質問は閉じられています。 編集または回答するには再度開いてください。

I am trying to add a symbolic matrix to cell array matrix using for loop but this error is coming: DOUBLE cannot convert the input expression into a double array.Can you please help me to resolve this issue?

1 回表示 (過去 30 日間)
Prateek jain
Prateek jain 2018 年 3 月 18 日
閉鎖済み: MATLAB Answer Bot 2021 年 8 月 20 日
Q=sym('Q',[8,1]);
prompt4='specify global external member joint force in [;] form'
Q=[0; 0; Q(3); Q(4); -2400; Q(6); 0 ;9600]
%specify global external member joint force%
Fall{1}= [-1200;1200;Q(3) - 1200;Q(4) - 1200];
Fall{2}=[ -Q(3);-Q(4);-2400;Q(6)]
Fall{3}=[2400;-Q(6); 0; 9600]
F=zeros(2*jo,1);
for i=1:1:8
for m=1:1:4
for t=1:3
p=c{t};
if p(m)==i
F(i)=F(i)+Fall{t}(m)
end
end
end
end

回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 3 月 18 日
You have
Q=sym('Q',[2*jo,1]);
Q=[0; 0; Q(3); Q(4); -2400; Q(6); 0 ;9600]
so Q has unresolved symbolic entries (not an error)
Then you have
qall{i}=T{i}*[Q(m);Q(m+1);Q(m+2);Q(m+3)]
so qall makes reference to those symbolic variables.
Then
Fall{i}=((f(i)*h)/12)*[6; -h; 6; h]+ qall{i};
so Fall{i} makes reference to those symbolic variables.
You never give a value to those symbolic entries, so by the time of
F(i)=F(i)+Fall{t}(m); %HERE
then those Q3 and so on are still unresolved. That prevents them from being converted into double precision values such as would be needed to add to F(i) which you initialized to double precision zeros.
If you use
F=zeros(2*jo,1,'sym');
then it happens that by the end of the loop that none of those variables will remain in F, but there are intermediate entries in F that use them. I do not know if it can be guaranteed that they will all cancel out.
  1 件のコメント
Prateek jain
Prateek jain 2018 年 3 月 18 日
Thanks Walter, I wanted my final F in symbolic form and using 'sym' works for it.
F=zeros(2*jo,1,'sym');

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by