Effacer les filtres
Effacer les filtres

can you solve this problem

2 vues (au cours des 30 derniers jours)
abdulaziz almutairi
abdulaziz almutairi le 26 Jan 2016
Commenté : Walter Roberson le 27 Jan 2016
I solved this problem but the file didn't run, the codes in the editor are:
function [s,ea,i]=SqRoot(a,eps,maxit)
i = 0;
s = a/2;
ea = 100;
while(1)
sold = s;
s= (s+a/s)/2;
i = i+1;
if s ~= 0, ea=abs((s - sold)/s)*100; end
if ea <= eps | i>= maxit, break, end
end
  5 commentaires
Star Strider
Star Strider le 27 Jan 2016
‘Did you see the attached photo?’
No, because no photo was attached.
Walter Roberson
Walter Roberson le 27 Jan 2016
a_arg = rand();
eps_arg = randn() / 10^8;
maxit_arg = randi([10,500]);
[s_ans, ea_ans, i_ans] = Student(a_arg, eps_arg, maxit_arg)

Connectez-vous pour commenter.

Réponses (1)

Star Strider
Star Strider le 26 Jan 2016
Your code runs for me, and produces the correct result:
a = 50; % Argument
maxit = 100; % Argument
i = 0;
s = a/2;
ea = 100;
while(1)
sold = s;
s= (s+a/s)/2;
i = i+1;
if s ~= 0, ea=abs((s - sold)/s)*100; end
if ea <= eps || i>= maxit, break, end
end
What problems are you having with it?

Catégories

En savoir plus sur Desktop dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by