summation of sinx using summation

์กฐํšŒ ์ˆ˜: 3 (์ตœ๊ทผ 30์ผ)
Abraham Robledo
Abraham Robledo 2019๋…„ 2์›” 21์ผ
๋‹ต๋ณ€: James Tursa 2019๋…„ 2์›” 22์ผ
I'm trying to find the value of ???(?) if ? = ? /2 using the following equation. Including 10, 20, 30, and 100 terms in the summation. As such ???(?) = ? โˆ’?^3/!+?^5 /5!โˆ’x^7/7!... I tried the following but its not working. The numbers are only odd indices. Please help
n = 10
x = pi/2;
y = zeros(1,n);
for i = 0:n
y(i+1) = (x^(i+1)/factorial(i+1));
end
SINx = sum(y)
=3.8105
  ๋Œ“๊ธ€ ์ˆ˜: 1
Walter Roberson
Walter Roberson 2019๋…„ 2์›” 22์ผ
0:n produces all of the indices, not just the odd indices. The odd indices would be 1:2:n when n is the final index, or 1:2:(2*n-1) to include n terms

๋Œ“๊ธ€์„ ๋‹ฌ๋ ค๋ฉด ๋กœ๊ทธ์ธํ•˜์‹ญ์‹œ์˜ค.

๋‹ต๋ณ€ (1๊ฐœ)

James Tursa
James Tursa 2019๋…„ 2์›” 22์ผ
You are missing the alternating signs of the terms. E.g., you could put in a factor of (-1)^something to get this effect. The "something" would be dependent on the loop index. Also, as Walter points out, you need the indexing for the powers of x and the factorial to step by 2, not step by 1.

์นดํ…Œ๊ณ ๋ฆฌ

Help Center ๋ฐ File Exchange์—์„œ Matrix Indexing์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์•Œ์•„๋ณด๊ธฐ

ํƒœ๊ทธ

Community Treasure Hunt

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

Start Hunting!

Translated by