calculate the sin of vect1 and display in degrees (not radians)

2 views (last 30 days)
I want calculate the sin of vect1 and display them in degrees(not radians),below is my codes, I am not sure it is right or not. Am I right? Is there better codes?
vect1=[1 2 4 6 3];
n1=sin(vect1);
for i=1:5
n1(1,i)=(i./(2.*pi)).*360;
end
disp('the sin of vect1 in degree is:');
disp(n1);
  1 Comment
Sainan Shi
Sainan Shi on 18 Feb 2017
and I have one more question : whether and how the command pi will make this more accurate?
Based the codes:
vect1=[1 2 4 6 3];
n1 = sind(vect1);
disp('the sin of vect1 degrees is:');
disp(n1);
the output is:
0.0175 0.0349 0.0698 0.1045 0.0523
But I saw the information:' For integers n, sind(n*180) is exactly zero, whereas sin(n*pi) reflects the accuracy of the floating point value of pi '
And if I use the command pi, like this:
vect1=[1 2 4 6 3];
n1 = sind(vect1*pi);
disp('the sin of vect1 degrees is:');
disp(n1);
the output is:
0.0548 0.1094 0.2176 0.3231 0.1638
the two output is different ,what is wrong? How can I use the command pi correctly ?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Feb 2017
vect1=[1 2 4 6 3];
n1 = sind(vect1);
disp('the sin of vect1 degrees is:');
disp(n1);
  3 Comments
Stephen23
Stephen23 on 18 Feb 2017
Edited: Stephen23 on 18 Feb 2017
If you want to use sin (and not sind) then you need to convert from degrees to radians:
>> sin(pi*vect1/180)
ans =
0.017452 0.034899 0.069756 0.10453 0.052336
But if those values are already in degrees then there is no point in converting them to radians for this caculation.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!