필터 지우기
필터 지우기

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 (최근 30일)
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.

답변 (1개)

Randy Acheson
Randy Acheson 2017년 4월 11일
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:

카테고리

Help CenterFile Exchange에서 Numbers and Precision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by