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

3 ビュー (過去 30 日間)
Dan
Dan 2013 年 11 月 26 日
回答済み: Dan 2013 年 11 月 26 日
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.

採用された回答

Walter Roberson
Walter Roberson 2013 年 11 月 26 日
mycos = inf;
while abs(mycos - cos(x)) > threshold

その他の回答 (1 件)

Dan
Dan 2013 年 11 月 26 日
Tank you very much Walter

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by