MATLAB Answers

The following error occurred converting from sym to double: Unable to convert expression into double array.

조회 수: 7(최근 30일)
Seb apple
Seb apple 2020년 6월 30일
답변: Aman Vyas 2020년 11월 5일
Hi, I am attempting to form a symbolic 2x2 matrixwith the following code, however i keep reciveing the error message "The following error occurred converting from sym to double: Unable to convert expression into double array. Error in untitled (line 31)A(n)=q.(A(n)+A(n+4))/(a-n^2);" Im not sure how to solve this can anyone help?
b= randi([0 1],101,1);
A=transpose(b);
A=[0,0,A,0,0]; %A vector with of length 101+4
t=0:1/104:1; %time axis with a sampling frquency of 100
sum=0;
x1=0:1/104:1;
syms a q
%cos part
for n=1:(length(t)-1)
x1=x1+ A(n)*cos(n*t(n))+A(n+1)*cos((n+1).*t(n));
end
subplot(5,1,1)
plot(t,x1); %Plot of x1
% sine part
B=A;
x2=0:1/104:1;
for n=1:(length(t)-1)
x2(n)= B(n)*sin(n*t(n));
end
subplot(5,1,2)
plot(t,x2);
% Transformation equation for A
%Variables
upperlim=length(A)-4;
for n=(1:upperlim)
A(n)=q.*(A(n)+A(n+4))/(a-n^2);
end
subplot(5,1,3)
plot(A,t);
% Transformation equation for B
upperlim=length(B)-4;
for n=(1:upperlim)
B(n)=((a-(n-2)^2)/q).*B(n+2)-B(n);
end
subplot(5,1,4)
plot(B,t);
M=[A(n) 0; 0 B(n)];
  댓글 수: 2
Seb apple
Seb apple 2020년 6월 30일
I am trying to make this code so that if a and q are symbolic and An and Bn are placed into a 2x2 matrix i can set the determinant ==0 thus allowing my to plot a and q implicitly against each other. would you be able to help?

댓글을 달려면 로그인하십시오.

답변(1개)

Aman Vyas
Aman Vyas 2020년 11월 5일
Hi ,
You can try by considering A(n) also as sym function since that is used in RHS. I tried from my end and was able to remove that error. For more information on sym you can follow:
Also the follow up issue in plot function can be resolved using fplot function.
Hope it helps !

Community Treasure Hunt

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

Start Hunting!

Translated by