Calculate the sin and cos of a value in radians (in one function)?

조회 수: 3 (최근 30일)
Jeremy Keoboupha
Jeremy Keoboupha 2016년 6월 13일
편집: Jeremy Keoboupha 2016년 7월 20일
I attempted to answer the question but I'm not sure if this is considered to be one function.
b = input('Enter a value ');
x=sin(b); y=cos(b);
disp('The sin of that value is ');
disp(x);
disp('The
cos of that value is ');
disp(y);
  댓글 수: 1
dpb
dpb 2016년 6월 13일
That isn't a function at all, but a script...
Wrap the computational part in a function to be called and name it something appropriate--*sincos* might suit... :)

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

채택된 답변

KSSV
KSSV 2016년 6월 13일
function sincos()
b = input('Enter the angle value in radians: ');
x=sin(b); y=cos(b);
fprintf('The sin of value %f is %f\n',b,x);
fprintf('The cos of value %f is %f\n',b,y);
  댓글 수: 2
Stephen23
Stephen23 2016년 6월 13일
편집: Stephen23 2016년 6월 13일
@Dr. Siva Srinivas Kolukula: Note that it is much more robust and secure to call input with its 's' option to return a string, this prevents evaluation of any arbitrary code that a user might enter, or from throwing unnecessary errors:
b = str2double(input('Enter the angle value in radians: ','s'));
Guillaume
Guillaume 2016년 6월 13일
편집: Guillaume 2016년 6월 13일
To see the security implications of input consider that if you enter
rmdir('c:\', 's')
to input without an 's' option, it will attempt to remove every folder on your C: drive.

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2016년 6월 13일
I speculate that the assignment is requesting that you build a series or taylor expansion that calculates sin and cos both.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by