Calculate the sin and cos of a value in radians (in one function)?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jeremy Keoboupha
am 13 Jun. 2016
Bearbeitet: Jeremy Keoboupha
am 20 Jul. 2016
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 Kommentar
dpb
am 13 Jun. 2016
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... :)
Akzeptierte Antwort
KSSV
am 13 Jun. 2016
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 Kommentare
Stephen23
am 13 Jun. 2016
Bearbeitet: Stephen23
am 13 Jun. 2016
@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'));
Weitere Antworten (1)
Walter Roberson
am 13 Jun. 2016
I speculate that the assignment is requesting that you build a series or taylor expansion that calculates sin and cos both.
0 Kommentare
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!