How to do this?.. new to matlab

조회 수: 6 (최근 30일)
androSLO
androSLO 2013년 3월 12일
First hey to everybody :)
I am new with Matlab and we have to do for homework some programs to create but i don't know really how to do it.. I had been reading on other forums and youtube but didn't see anything usefull... I would be very grateful if somebody could write me this program to help me. Program:
I have to calculate function sin(x) with help of line on 6 decimals exactly and value compare with Matlab function. Do the same for cos(x)..
sin(x)=x/1!-x^2/3!+x^5/5!-x^7/7!+⋯ and cos(x)= 1-x^2/2!+x^4/4!-x^6/5!+⋯
Please if somebody can help :) Thank you in advance.
Andrej

답변 (1개)

Image Analyst
Image Analyst 2013년 3월 12일
Hint, create a variable called sinx that will be the sum of all the terms. Then sum the individual terms into it in a loop. Use factorial(n).
x = 1.234; % Whatever...
sinx = 0;
for k = 1 to 100
sinx = sinx + x^ ...... % Use k and factorial(k).
end
fprintf('The value of sin(%f) = %f', x, sinx);
  댓글 수: 2
androSLO
androSLO 2013년 3월 12일
hm... i have tried something but it doesn't work.. i understand what to write in line 4 for sinx..but what is with X? put i these numbers which have you gave me or how...because i am doing on matlab only for two days till now...
Walter Roberson
Walter Roberson 2013년 3월 12일
X would be the value whose sin() or cos() you were calculating.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by