Question

Write a MATLAB script, which asks the user to input the angle xd (in deg) and then approximates sine of the angle using the first 5 terms of Taylor series as follows: n+12n-1 sin n-1 (2n-1)! 1 Note that x in Taylors equation is in radian, so make sure to do the conversion first Start with defining the vector n=1:5 and then use element-wise operation and basic MATLAB commands to calculate the summation. To calculate the factorial of any number, you may use factorial function in MATLAB. Check your code for input xd-38 and compare the result to sind(38) Use fprintf to report the results on the screen
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code:

clc
deg = input('Enter the angle(in deg):');
y = 0;
x = deg*pi/180;
for i=1:5
y= y+((-1)^(i+1))*(x)^((2*i)-1)/factorial((2*i)-1);
end
z = sind(deg);
% printing the y and z value for comparison
fprintf('Value using code=%f \n Value using sind() function=%f\n',y,z);

Output:

Enter the angle(in deg):38
Value using code=0.615661
Value using sind() function=0.615661

1-clc 2deg -input (Enter the angle (in deg) : ) 3- y=0; 4- x=deg *pi/180; 5- for i=1:5 6y- y+((-1) (1+1))(x) ((2*i)-1)/factorial((2*1)-1) 7-end 8- z = sind (deg); % printing the y and z value for comparison fprintf(Value 10- using code=% f \n value using sind) function fin,y,z:

Add a comment
Know the answer?
Add Answer to:
Write a MATLAB script, which asks the user to input the angle xd (in deg) and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Matlab, write a script which asks a user to input numbers until the user inputs...

    In Matlab, write a script which asks a user to input numbers until the user inputs 0. Then the script should print only the positive numbers entered by the user, in reverse order. For example, if the user inputs “4,-1,5,2,-3,-8,0” the script should print “2,5,4”.

  • Write a script in matlab that prompts the user to input the day, month, and year;...

    Write a script in matlab that prompts the user to input the day, month, and year; determine the day of the year (the number of days including the current day). Be sure to take leap year into account. Use a for loop Test your code on the following dates: February 28, 2015 April 9, 1976 October 12, 1887 Create a script that performs the same function as repmat. The only built-in commands you may use are input, size, and disp.

  • Write a Matlab script that asks the user for two angles in degrees and stores them...

    Write a Matlab script that asks the user for two angles in degrees and stores them as variables. Calculate and store the cosines of the numbers (they must be converted to radians to use Matlab's cos function). Use a conditional statement and fprintf to print the larger of the two cosine values and the angle (in degrees) that resulted in that value. If they are equal, print a message to the effect that the cosines of the two angles (print...

  • USING MATLAB Write a script that asks the user to input a sentence. It then replaces...

    USING MATLAB Write a script that asks the user to input a sentence. It then replaces all instance of 'he', 'she', 'He', or 'She' with 'Mr. Meseeks' and prints out the new sentence. . HINT: Use 'strrep' and 'lower' function.

  • This question is for MATLAB. Write a script that continuously asks the user for a new...

    This question is for MATLAB. Write a script that continuously asks the user for a new sentence, until the user types the word "STOP". The program records all of the sentences the user wrote (not including "STOP") in a matrix with as many rows as needed but with an N number of columns. The user is prompted to provide N before typing in the first sentence. The output of the program is the array with the sentences in it, in...

  • DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the...

    DO THIS IN MATLAB PLEASE DO THIS IN MATLAB Create a script file that performs the following calculations. Your script will use the functions you create. Label all graphs appropriately. For this project, do not have your homemade functions fprintf anything, instead have all your fprintf commands within your script. Attach your published script file along with .m files for your functions. Exercise 1. A fundamental iterative method for finding the roots of equations of one-variable is known as Newton's...

  • Use matlab and write script: Please use n = input('Enter the value of n :') not...

    Use matlab and write script: Please use n = input('Enter the value of n :') not the function command. Consider the following equation 6a + 9b + 20c = n The variables a, b, and c can be thought of as the number (non-negative integers) of 6’s, 9’s, and 20’s in n. Note that for a given n, there might be one, multiple, or no solutions for a, b, and c. For example, n = 15 → a = 1...

  • using matlab, write a script for the following that prompts the user to input the amount...

    using matlab, write a script for the following that prompts the user to input the amount of cases bought as a vector, calculates the cost, and stores the correspondind cost in a row beneath the demand: the price of produce is calculated as follows: if 30 cases of oranges are bought, the cost is 4 dollars per case if more than 30, but less than 100 cases are bought, the cost is 10 for the first 30 cases, then 3...

  • Write a script that prompts the user to enter a value n (n > 6) that...

    Write a script that prompts the user to enter a value n (n > 6) that will generate an n element vector of random integers between 0 and 100 that will represent quiz grades. Then have the script calculate the average of the quizzes where the smallest grade is dropped. Then script will display the average of the quizzes along with the highest quiz grade. Given the following system of equations: 8s - 11t + 7u + 5v - w...

  • answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for...

    answer 4, 5, 6, 7 using matlab Homework 10 1. Write the correct first-line syntax for a user defined function that is named Feynman and has input variables q and e, and outputs L and M. (Comment out of this line). 2. Using zeros, ones, and eye commands write the one line syntax to create the following matrix: 00000 01100 01010 01001 3. Write the syntax for the user defined function that calculates the surface area and volume of a...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT