The following error occurred converting from sym to double: Unable to convert expression into double array.
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Aman Vyas
on 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 !
0 Comments
See Also
Categories
Find more on Numbers and Precision in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!