Create matrix from columns of variable (a)-for loop
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Wazy sky
el 26 de Sept. de 2018
Respondida: Wazy sky
el 13 de Oct. de 2018
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
2 comentarios
Respuesta aceptada
Walter Roberson
el 26 de Sept. de 2018
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.
16 comentarios
Stephen23
el 11 de Oct. de 2018
"Your suggestions are so much appreacited"
Your code is very badly aligned. Badly aligned code is one way that beginners hide bugs in their code. In this case, your badly aligned code has hidden several bugs and made them harder to identify. Correctly aligned code makes identifying some kinds of bugs easier. You should align your code correctly.
I recommend using the MATLAB Editor's default alignment settings, which occur automatically as you type. You can also align existing code: select the code text, press ctrl+i.
Más respuestas (2)
Wazy sky
el 11 de Oct. de 2018
Editada: Walter Roberson
el 11 de Oct. de 2018
2 comentarios
Walter Roberson
el 11 de Oct. de 2018
If you dbstop at the vpasolve() and examine vpa(EmE) then you will see that it has a large number of real constants times real() or imag() of various variables, added together, with no obvious cross-products or exponentiation or exp() or the like. So each row is linear in real() and imag() of those variables. But each row also ends in a constant that has both a real and an imaginary coefficient. With all of those constants being real valued, and with real() and imag() also returning real-valued information, then the part involving the variables must be real-valued. That means there is no possibility of part of a term canceling out the imaginary part of the constant coefficient of the row. Therefore the rows cannot equal 0, because although you might balance the real portion, you are left with a non-zero imaginary portion.
Ver también
Categorías
Más información sobre Conversion Between Symbolic and Numeric en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!