MATLAB: Create matrix from columns of variable (a)-for loop

for loopmatrixsymbolic matrixvariable

Hi I want to create a matrix TA from the columns EE generated in the last loop. I can display the wanted columns "disp (EE)' but when adding the matrix want to create from these columns, an error occurred, noted that the vectors/columns EE has a variable (a)
You may ignore the lines of the code before the line start with C = [I;A;B]; for getting the question
I=ones(20,2);
for i=0:20
theta=(pi/40)*i;
r=2.5;x1=r*cos(theta);
y1=r*sin(theta);s=i+1;
I(s,:)=[x1,y1];
end
A=ones(20,2);
for k=1:20
r=(k-1)/10;
A(k,:)=[1,r];
end
m=1:-(1/47):0;
B=ones(length(m),2);
B(:,1)=m';B(:,2)=2;
C = [I;A;B];
%%find the complex variable matrix, ZC connjgate Z
Z=ones(length(C),1);
for v=1:length(C)
Z(v)=C(v,1)+1i*C(v,2);end
ZC=conj(Z);
F=ones(89,2);syms Fb;
for ii=1:89
if ii<22
F(ii,1)=0;F(ii,2)=0;
elseif ii<42
F(ii,1)=1; F(ii,2)=0;
else
F(ii,1)=(89-ii)/(89-42);F(ii,2)=0;
end
end
FF=F.*Fb;
zzc=Z-ZC;
QQ=ones(length(Z),21);SS=ones(length(Z),21);ss=0;
T1=ones(length(Z),21);T2=ones(length(Z),21);syms a
for K=-6:14
ss=ss+1;
QQ(:,ss)=Z.^(2*K-1)+ZC.^(2*K-1);
SS(:,ss)=(2*ss-1)*(Z.^(2*ss-2));
T1(:,ss)=Z.^(2*K-2);T2(:,ss)=ZC.^(2*K-2);
end
%multiplying the T1,T2 BY THE FCTOR
Q=QQ.';S=SS.';
TA=ones(89,21);TB=ones(89,21);
Tz=sqrt(Z.^2-a^2); Tzc=sqrt(ZC.^2-a^2);
for j=1:21
CC=Tz.*T1(:,j);DD=Tzc.*T2(:,j);EE=CC+DD;
TA(:,j)=EE;
end

Best Answer

syms a
so a is syms
Tz=sqrt(Z.^2-a^2); Tzc=sqrt(ZC.^2-a^2);
so Tz and Tzc are syms involving the unresolved variable a
CC=Tz.*T1(:,j);DD=Tzc.*T2(:,j);EE=CC+DD;
so CC and DD and EE all involve that unresolved variable a
TA=ones(89,21);
so TA can only store numeric values.
TA(:,j)=EE;
with TA only being able to store numeric values, the values in EE have to be converted from sym to numeric. But they cannot be converted, because they involve the unresolved symbolic variable a
Your EE entries are formulas, such as
(5209627982755595*(7990063086789097/36028797018963968 - a^2)^(1/2))/137438953472 + (5252908098854583*(6546788930781455/18014398509481984 - a^2)^(1/2))/4398046511104
You cannot store a formula in a numeric array.
You can use vpa() to convert the formulas from using rational numbers to using floating point numbers; for example vpa() of the above gives the result
1194.3730212020871022104984149337*(0.36341979041573407860354905096756 - 1.0*a^2)^(1/2) + 37905.032388193612860050052404404*(0.22176880017902014796682408359629 - 1.0*a^2)^(1/2)
but this is still a formula and would need a symbolic array to be stored into.
Related Question