use the for or while looping to the series S=4*[sin(theata)/1 +sin(3thea​ta)/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

2 Ansichten (letzte 30 Tage)
S=4*[sin(theata)/1 +sin(3theata)/3+sin(5theata)/5+.....]

Akzeptierte Antwort

Youssef  Khmou
Youssef Khmou am 15 Apr. 2013
Bearbeitet: Youssef Khmou am 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.....
  3 Kommentare
Image Analyst
Image Analyst am 15 Apr. 2013
We're trying to help you without doing your homework outright for you. We've seen very little code by you so far. I'm sure you don't want to just turn in our code as your own, so post some code we can help with by giving hints.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Image Analyst
Image Analyst am 15 Apr. 2013
Hint, have a loop over k and calculate sin(k*theata)/k in the loop. I hope that's not doing too much of your homework for you. You still have to make the loop and sum up the term in the loop into the overall sum and then multiply that by 4.
  2 Kommentare
majid
majid am 15 Apr. 2013
Bearbeitet: Image Analyst am 15 Apr. 2013
sum=0;
k=1;
while o<theata<pi
s(k)=sin(k*theata)/k;
sum=sum+k;
k=k+1;
sum=4*sum;
Note:I want to now how I can do the odd number in series,Also he asked for
i. The number of iterations it took to converge according to above set criterion. ii. The value of the final term. iii. The value of the sum of the series. Plot the sum of series for first 2000 iterations.
Image Analyst
Image Analyst am 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.

Melden Sie sich an, um zu kommentieren.


Carlos
Carlos am 15 Apr. 2013
Bearbeitet: Carlos am 15 Apr. 2013
Try this
theata=pi/2;
a=1;
S=0;
n=1;
while (a>10e-6)
a=sin(n*theata)/n;
S=S+a;
n=n+2;
end
S=4*S;
  2 Kommentare
majid
majid am 15 Apr. 2013
use theata= 0.7 degrees. Then Print:
i. The number of iterations it took to converge according to above set criterion. ii. The value of the final term. iii. The value of the sum of the series. Plot the sum of series for first 2000 iterations.
Carlos
Carlos am 15 Apr. 2013
Sorry, I misunderstood the question, I thought theata should be a fixed value.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by