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

3 Ansichten (letzte 30 Tage)
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 Kommentare
Seb apple
Seb apple am 30 Jun. 2020
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?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Aman Vyas
Aman Vyas am 5 Nov. 2020
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