can anyone find the bug in my 3 line code.

1 次查看(过去 30 天)
for n = −20:20 % Compute Fourier series coefficients
c(n + 21) = quad(@(x)(exp(sin(x).ˆ6).*exp(−1i*x*n)),0,pi,1e−4);
end
I get the following error when I run the above code
??? Error: File: D:\install\work\test\small.m Line: 1 Column: 8 Missing variable or function.

采纳的回答

Sean de Wolski
Sean de Wolski 2011-6-28
clear
for n = -20:20 % Compute Fourier series coefficients
c(n + 21) = quad(@(x)(exp(sin(x).^6).*exp(-1i*x*n)),0,pi,1e-4);
end
copied and pasted works on my system. You're not showing us everything.
  10 个评论
Sean de Wolski
Sean de Wolski 2011-6-28
No. It's probably because of what Jan said in that you had unexpected characters (minus sign), possibly keyboard artifacts or bad copying and pasting, I'm not sure. However, I'll bet if you looked at the editor you'll see a red squiggly line under some of the characters with an mlint message "invalid characters" if you hover your mouse over it?
Neels
Neels 2011-6-28
I tried it again with the old script again. I still cannot find any of the those hint of errors. any way i shall try it again. thanks

请先登录,再进行评论。

更多回答(2 个)

Jan
Jan 2011-6-28
for n = 20:20
??? Error: File: D:\install\work\test\small.m
Line: 1 Column: 8 Missing variable or function.
Line 1 column 8 is a "−" (mdash), not a "-" (minus). The same problem appears in the second line. And as Sean de found out: "ˆ" is not "^".
How did you create this piece of code? Did you copy it from a PDF file?
  2 个评论
Neels
Neels 2011-6-28
thanks, i was just trying to test some pre-existing code in the web to check numerical integration. but still it shows the error

请先登录,再进行评论。


Paulo Silva
Paulo Silva 2011-6-28
for n = -20:20 % Compute Fourier series coefficients
c(n + 21) = quad(@(x)(exp(sin(x).^6).*exp(-i*x*n)),0,pi,1e-4);
end
Just a few weird symbols and -1i should be just -i
  3 个评论
Neels
Neels 2011-6-28
thanks, but even after i change it, it shows the same error
Paulo Silva
Paulo Silva 2011-6-28
Hi Sean you are correct, I never used 1i with MATLAB and it does work, we learn something new everyday, thanks

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Environment and Settings 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by