can anyone find the bug in my 3 line code.
Show older comments
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.
Accepted Answer
More Answers (2)
Jan
on 28 Jun 2011
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?
Paulo Silva
on 28 Jun 2011
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 Comments
Sean de Wolski
on 28 Jun 2011
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
on 28 Jun 2011
Paulo Silva
on 28 Jun 2011
Hi Sean you are correct, I never used 1i with MATLAB and it does work, we learn something new everyday, thanks
Categories
Find more on Scripts in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!