Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please include a SCREENSHOT OF THE MATLAB to show the coding inputs if possible. In a script file named LASTNAME_LAB10_TASK1.m, write a program according to
Please include a SCREENSHOT OF THE MATLAB to show the coding inputs if possible.
In a script file named LASTNAME_LAB10_TASK1.m, write a program according to the specifications outlined below. Before starting, clear all variables in the MATLAB Workspace and the contents o MATLAB Command Window. Unless specified, suppress all MATLAB Command Window output. Upon completion, the result of executing your program should look similar to the output shown below. >> LASTNAME_LAB10_TASK1 Enter a value for x (in radians): 2 Enter a threshold in the range (0, 1): -1 Invalid threshold, please ! Enter a threshold value in the range (0, 1): 0 Invalid threshold, please ! Enter a threshold value in the range (0, 1): 1.3 Invalid threshold, please ! Enter a threshold value in the range (0, 1): 1e-5 cos(2, 000000) = -0.4161468365 cosApprox(2.000000) = -0. 4161552028 Number of terms = 6 >LASTNAME_LAB10_TASK1 Enter a value for x (in radians): pi/2 Enter a threshold in the range (0, 1): 1e-4 cos(1.570796) = 0.0000000000 cosApprox(1.570796) = 0.0000247373 Number of terms = 5 >> LASTNAME_LAB10_TASK1 Enter a value for x (in radians): 0.0 Enter a threshold in the range (0, 1): 1e - 7 cos(0.000000) = 1.0000000000 cosApprox(0.000000) = 1.0000000000 Number of terms = 1 Create a scalar variable named x and assign to it a value obtained by prompting with the prompt string 'Enter a value for x (in radians): '. (b) Create a scalar variable named threshold and assign to it a value obtained by prompting the user with the prompt string. "Enter a threshold in the range (0, 1): '. Use a while-end statement to continuously prompt the user until the user enters a valid value for the threshold. You may assume the user will always enter a numerical value. (c) Using another while-end statement to perform the following e value for cos(x) using the summation formula given below. cos Approx(x) almostequalto + x^0/0! - x^2/2! + x^4/4! - x^6/6! + For the value of x entered by the user, accumulate terms of the formula for cosApprox(x) until the absolute value of the difference between the summation of cosApprox(x) and the actual value of cos(x) is less than or equal to the threshold. Compute how many terms were accumulated to achieve the accuracy as determined by the threshold value entered by the user. Use multiple instances of the built-in fprintf() function to display to the Command Window the value of cos(x), the value of cosApprox(x), and the number of terms used for the accumulation. Format the values of cos(x) and cosApprox(x) as fixed-point real numbers showing a maximum of 10 digits after the decimal point. Format the number of accumulated terms as an integer. Thoroughly test your program with more than those input sequences shown in the sample output aboveStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started