Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

How do I create a loop for this expression?

1 Ansicht (letzte 30 Tage)
James Smith
James Smith am 1 Dez. 2019
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
Basically we have xn+1 = 1/2(xn+(a/xn))
stop if n=N where |x^2N −a|<e. e is max error
Here is my working so far i dont understand how to create a loop for this iteration
a=input('Enter a value for a')
e=input('Enter a value for e')
x0=input('Enter a value for x0')
% if n = 0
x = x0
for n = 1:(N-1)
steps = 0
% iteration counter
if mod((xN)^2 -a) < N
end if n=N
i want to get a lot of values to estimate root(a) but i've made mistakes not sure how to fix

Antworten (1)

Thiago Henrique Gomes Lobato
Those modifications fix your code. Your fogot the actually equation in the iteration and had some variables misplaced.
a=input('Enter a value for a \n');
e=input('Enter a value for e \n');
x0=input('Enter a value for x0 \n');
N=input('Enter a value for N max \n');
x = x0
for n = 1:(N-1)
x = 1/2*(x+(a/x));
% iteration counter
if abs((x)^2 -a) < e
NofIterations = n;
break
end
end
NofIterations
rootFromA = x

Diese Frage ist geschlossen.

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by