While-end statement using factorial(),abs() and cos()

3 views (last 30 days)
I am having trouble understanding what I need to accomplish in part c of this lab. This is my code so far.
if true%
clear all;
clc;
close all;
x=input('Enter a value for x (in radians): ');
threshold=input('Enter a threshold in the range (0,1): ');
while ( threshold < 0 || threshold > 1)
fprintf('Incorrect input, please try again.\n');
threshold = input ('Enter a threshold in the range (0,1): ');
end
How would I that formula?? I already have the user input x and threshold value. I need to use a while loop to compare the value of mycos(x) and cos(x) until the difference between the two is less than or equal to the threshold value entered by the user. Then I need to determine the number of terms summed to achieve the accuracy...
Really not sure where to start on this part. The while loop it a lot more complex then the loop used for the previous step. Any help would be greatly appreciated.
while (mycos(x) - cos(x) <= threshold)<--really not sure how to start and why I need to use factoral, abs.

Accepted Answer

Walter Roberson
Walter Roberson on 26 Nov 2013
mycos = inf;
while abs(mycos - cos(x)) > threshold

More Answers (1)

Dan
Dan on 26 Nov 2013
Tank you very much Walter

Community Treasure Hunt

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

Start Hunting!