Asked by HADIMARGO
on 13 Dec 2018

my code:

s=0;

for n=1:0.01:10

s=s+(-1^n+1*sin(n*pi*x));

end

f=(2/pi)*s;

plot(x,f)

Where is wrong in my code?

Answer by madhan ravi
on 13 Dec 2018

x=linspace(-5,5,10000);

s=0;

for n=1:0.01:10

s=s+(-1^n+1*sin(n*pi*x));

end

f=(2/pi)*s;

plot(x,f)

Opportunities for recent engineering grads.

Apply Today
## 4 Comments

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/435495-how-should-draw-this-in-loop-form-where-is-the-problem-in-my-code#comment_649977

## HADIMARGO (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/435495-how-should-draw-this-in-loop-form-where-is-the-problem-in-my-code#comment_649991

## Walter Roberson (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/435495-how-should-draw-this-in-loop-form-where-is-the-problem-in-my-code#comment_649993

## HADIMARGO (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/435495-how-should-draw-this-in-loop-form-where-is-the-problem-in-my-code#comment_650018

Sign in to comment.