Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
263 B
0
Indexable
Never
f = @(x) x*x*x - 5*x + 1;
x0 = 0;
x1 = 1;
tollarable_error = 0.00001;

for i=1:100
  x2 = x1 - ((x1-x0) *f(x1)) / (f(x1) - f(x0));
  fprintf("Root %d = %f \n", i, x2);
  
  if abs(x2-x1) < tollarable_error
    break;
  endif
    x0 = x1;
    x1 = x2;
endfor

  

Leave a Comment