can anyone find the bug in my 3 line code.

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일

0 개 추천

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

Neels
Neels 2011년 6월 28일
thats all, i still get the same error
Neels
Neels 2011년 6월 28일
there is nothing extra in my code.
Sean de Wolski
Sean de Wolski 2011년 6월 28일
Neels, copy and paste what I have above into your editor; and run it. Report the full error message.
Neels
Neels 2011년 6월 28일
??? 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일
did you copy and paste it into a new editor window, not 'small' which has errors?
Neels
Neels 2011년 6월 28일
thanks Sean de, it doesn't give me an error. But there is also no answer. The command window just shows a prompt
Sean de Wolski
Sean de Wolski 2011년 6월 28일
yes; that's expected since you have output suppressed (a good thing)
disp(c)
to view some output
Neels
Neels 2011년 6월 28일
Thanks you very much, Sean de. I get the result now. was the error because of some previously stored values in the variables?
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일

1 개 추천

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

Sean de Wolski
Sean de Wolski 2011년 6월 28일
I had to change toe carrot ^ too.
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일

0 개 추천

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

Sean de Wolski
Sean de Wolski 2011년 6월 28일
Paulo, on some systems, mine included, it's recommended to use 1i as the imaginary component since it won't be overwritten.
Try putting this in an editor to see if mlint tells you
clear i x
x = 3+4*i
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

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Programming에 대해 자세히 알아보기

질문:

2011년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by