In: Mechanical Engineering
The function Sine is defined as:
where x is an angle in radians
Write a Matlab script program to compute the sinus value of any angle as the following:
- The program should run always until the user enters - 1 to exit from the program.
- A sk user to enter: Number of elements (N) that should be included in the sum
- C heck that N is a positive integer . [ Hint: use ( round (N) - N) or mod(N,1) ]
- A sk user to select to enter the angle, X , in degrees or radians
- A sk user to enter the value of X , it could be scalar or vector .
- Using switch/if and loops, calculate the value of sin(X).
- P rint the angle in degrees, the equivalent angle in radians and the sinus value for this angle.
clear all
value=0;
digit='Please enter a digit'
p=input(digit);
%To make sure that the program runs till -1 is entered, we use a while loop%
while(p~=-1)
elements='Enter no of elements to be included in the sum'
N=input(elements);
a=round(N); %This will round off the number to the nearest
integer%
if(a>=0)
disp('The no is a positive integer')
else
disp('The no is a negative integer')
end
%Now to get an angle from user and find the sine%
type='Type 1 if angle being entered is in radian and type 2 if
it is in degree'
b=input(type);
ang='Enter angle'
x=input(ang);
if(b==1) %If angle entered is in radian%
value=sin(x);
deg=57.2958*x;
disp('Angle in radians is')
disp(x)
disp('Equivalent angle in degree is')
disp(deg)
disp('Value of sin(x)=')
disp(value)
elseif(b==2) %If angle entered is in degree%
rad=0.0174533*x;
value=sin(rad);
disp('Angle in degree is')
disp(x)
disp('Equivalent angle in radian is')
disp(rad)
disp('Value of sin(x)=')
disp(value)
end
end