Question

In: Mechanical Engineering

The function Sine is defined as: where x is an angle in radians Write a Matlab...

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.   

Solutions

Expert Solution

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


Related Solutions

Write a program that asks the user for an angle, entered in radians. The program should...
Write a program that asks the user for an angle, entered in radians. The program should then display the sine, cosine, and tangent of the angle. (Use the sin, cos, and tan library functions to determine these values.) The output should be displayed in fixed-point notation, rounded to four decimal places of precision Take your previous Angle Calculator program and modify it to do a table of trig values. The columns will be: Degrees, Sine, Cosine, Tangent,. And the rows...
Where is the function ln(sin x ) defined and continuous?
Where is the function ln(sin x ) defined and continuous?
MATLAB Write a user defined function for a projectile motion. If a ball is launched from...
MATLAB Write a user defined function for a projectile motion. If a ball is launched from initial position(0,0) with a velocity v0 at angle θ, determine your horizontal and vertical position. Please plot x vs. t, y vs. t and y vs. x.
This code is to be written in Matlab. Write a function that will plot cos(x) for...
This code is to be written in Matlab. Write a function that will plot cos(x) for x values ranging from -pi to pi in steps of 0.1, using black *'s. It will do this three times across in one Figure Window, with varying line widths. If no arguments are passed to the function, the line widths will be 1, 2, and 3. If on the other hand, an argument is passed to the function, it is multiplier for these values....
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and...
Please solve the following problem for MATLAB Write a user-defined function that calculates the average and the standard deviation of a list of numbers. Use the function to calculate the average and the standard deviation of the following list of grades : 80 75 91 60 79 89 65 80 95 50 81
Please solve the following problem for MATLAB Write a user-defined function (name it F to C)...
Please solve the following problem for MATLAB Write a user-defined function (name it F to C) that converts temperature in degrees F to temperature in degrees C. Use the function to solve the following problem. The change in the length of an object, ∆L, due to a change in the temperature, ∆T, is given by: ∆L = αL∆T, where a is the coefficient of thermal expansion. Determine the change in the area of a rectangular(4.5 m by 2.25m) aluminum (α=23·10-61/˚C)...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height...
Write a user-defined MATLAB function, with two input and two output arguments that determines the height in centimeters (cm) and mass in kilograms (kg)of a person from his height in inches (in.) and weight in pounds (lb). (a) Determine in SI units the height and mass of a 5 ft.15 in. person who weight 180 lb. (b) Determine your own height and weight in SI units.
Matlab Create/write a function that takes an input of x and y data, and a string...
Matlab Create/write a function that takes an input of x and y data, and a string (either linear? or quadratic), sets up a linear system of equations (Ax = b), and solves and plots the model.
Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name...
Write a user-defined MATLAB function that converts real numbers in decimal form to binary form. Name the function b = deciTObina (d), where the input argument d is the number to be converted and the output argument b is a 30-element-long vector with 1s and 0s that represents the number in binary form. The first 15 elements of b store the digits to the left of the decimal point, and the last 15 elements of b store the digits to...
1. Locate a root of sin(x)=x2 where x is in radians. Use a graphical technique and...
1. Locate a root of sin(x)=x2 where x is in radians. Use a graphical technique and bisection with the initial interval from 0.5 to 1. Perform the computation until ea is less than es=2%. Also perform an error check by substituting your final answer into the original equation. 2. Determine the positive real root of ln(x 2 )=0.7 using three iterations of the bisection method, with initial interval of [0.5:2]. 3. Determine the lowest positive root of f(x)=7sin(x)e -x -1...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT