# use the for or while looping to the series S=4*[sin(theata)/1 +sin(3theata)/3+sin(5theata)/5+.....] ,,in the range 0<theata<pi with error bound of 10^-6..?....please help me to solve this question in the earliest opportunity

1 view (last 30 days)

Show older comments

S=4*[sin(theata)/1 +sin(3theata)/3+sin(5theata)/5+.....]

##### 0 Comments

### Accepted Answer

Youssef Khmou
on 15 Apr 2013

Edited: Youssef Khmou
on 15 Apr 2013

Try this version :

% theta=0:pi/30:pi;

theta=0:0.01:2*pi;

S=0;

tolerance=1e-6;

n=1;

r=6; % random

counter=1;

while r>tolerance

N1=norm(S);

S=S+sin(n*theta)/n;

N2=norm(S);

r=abs(N2-N1);

n=n+2;

counter=counter+1;

end

plot(theta,S);

axis([0 4 0 1])

grid on

Now it approximates well the rectangle, the number of iterations is saved in the variable 'counter', finish the code with the desired prints .

To conclude you work, there a special name of the infinitesimal waves nears the edges , that phenomenon has a special name , it starts with G.....

### More Answers (2)

Image Analyst
on 15 Apr 2013

##### 2 Comments

Image Analyst
on 15 Apr 2013

Use a for loop instead of a while loop. Have an outer for loop over theata.

for theata = 0: 0.01 : pi

Don't use "sum" since that is a built in function name and you'll be destroying it. Use S like you started to. Finally you need to calculate the "true" value (whatever that is) and compare it to S and bail out of your inner for loop once the error is less than 1E-6.

### See Also

### Community Treasure Hunt

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

Start Hunting!