MATLAB Answers

Unable to convert expression into double array

21 ビュー (過去 30 日間)
Cameron Rampersadh
Cameron Rampersadh 2021 年 4 月 8 日 6:58
コメント済み: Cameron Rampersadh 2021 年 4 月 8 日 10:12
Following code produces the error for 'while abs(double(subs(diff))) < 1/10'
syms f(t)
syms t
syms n
T = 2*pi;
w1 = 1;
t2 = linspace(-1, 1, 10);
f(t) = piecewise(-pi<t<0, (4+t)/2, 0<=t<pi, (2-t).*cos(2*t));
Cn = (int(f(t) * exp(-1j * n * w1 * t), -T/2, T/2))/T;
n = 1;
f(t2);
diff = 0;
while abs(double(subs(diff))) < 1/10
Cn = (int(f(t) * exp(-1j * n * w1 * t2), -T/2, T/2))/T
Sn = Cn.*exp(1j * n * w1 * t);
diff = abs(f(t2)-Sn)
diff = simplify(diff)
diff = vpa(diff)
n = n + 1;
end
n
Anyone know what i can do? Cheers

回答 (2 件)

KSSV
KSSV 2021 年 4 月 8 日 7:17
This line:
subs(diff)
You have to substitute some value right? I guess you need to input value of t here......
  1 件のコメント
Cameron Rampersadh
Cameron Rampersadh 2021 年 4 月 8 日 10:12
I need to calculate the difference between f(t2) and Sn, and if their difference is greater than 1/10, the while loop needs to be exited and displays what value of n the while loop got up to. Hence, putting diff in the while loop. I have changed diff to another variable name as ive just learnt that it is a standard matlab function.

サインインしてコメントする。


VBBV
VBBV 2021 年 4 月 8 日 9:55
編集済み: VBBV 2021 年 4 月 8 日 9:55
diff
is a standard matlab function. Use another variable name. Do you want to take diff of some variable? E.g. t2
Like KSSV said you require a variable to substitute for a value.
  1 件のコメント
Cameron Rampersadh
Cameron Rampersadh 2021 年 4 月 8 日 10:10
Hi,
I changed the variabl diff to another variable, 'difference', but still no luck :(

サインインしてコメントする。

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by