Answer by madhan ravi
on 7 Dec 2018

Edited by madhan ravi
on 7 Dec 2018

Use cumsum() to define the behaviour of the alternating series:

x=linspace(0,50,10000);

n=1:10000;

y=(2/pi).*cumsum((((-1).^n+1).*(sin(pi.*x)))./n);

figure(1);

plot(x,y)

HADIMARGO
on 7 Dec 2018

madhan ravi
on 7 Dec 2018

Anytime :) , read more about cumsum() and linspace()

Sign in to comment.

Answer by HADIMARGO
on 8 Dec 2018

my teacher say it isnot correct. you should put it in a loop.

Walter Roberson
on 8 Dec 2018

If you have TheResult = cumsum(SomeVector) then you can recode that in a loop as

TheResult(1) = SomeVector(1);

for LoopVariable = 2 : length(SomeVector)

TheResult(LoopVariable) = TheResult(LoopVariable-1) + SomeVector(LoopVariable);

end

... Approximately.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## madhan ravi (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/434485-how-i-could-draw-this-function#comment_647685

## HADIMARGO (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/434485-how-i-could-draw-this-function#comment_647688

Sign in to comment.