Filter löschen
Filter löschen

i used syms so i can find an expresssion for Cn in terms of n, but then i get this error (Conversion to logical from sym is not possible.). i have read online that vpa cancel this so incorporated this (i might be wrong). I'm newbie to matlab sorry.

2 Ansichten (letzte 30 Tage)
syms n
syms t
f1=(1-cos(t)).^2;
f2=(t/pi).^2;
energy1=int(f1,-pi,0);
energy2=int(f2,0,pi);
energy=(1/(2*pi))*(energy1+energy2);
% for n is not equal to 0.
if true
% code
end
C1e=(1-cos(t))*exp(-1j*n*t);
C2e=(t/pi)*exp(-1j*n*t);
Cn1=int(C1e,t,-pi,0);
Cn2=int(C2e,t,0,pi);
Cn_total=1/(2*pi)*(Cn1 + Cn2);
vpa(Cn_total);
C0n=0.75000000000000004636678955634159;
approx=(abs(C0n)).^2;
vpa(approx)
energy99=0.99.*energy;
vpa(energy99);
Coefficientn=2.*(abs(Cn_total)).^2;
vpa(Coefficientn);
while approx<energy99
approx=approx+Coefficientn;
n=n+1;
end
Conversion to logical from sym is not possible.

Antworten (1)

Randy Acheson
Randy Acheson am 11 Apr. 2017
The issue here is that you are trying to compare a numeric value and a symbolic value in your while loop. While 'approx' and 'energy99' are numeric to begin with, when you append 'Coefficientn' to approx, it becomes symbolic. In order to compare these two values, you will need to use the 'subs' function to substitute your variable values.
For more information, see this MATLAB Answers post:

Community Treasure Hunt

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

Start Hunting!

Translated by