Plotting approximation error in Newton-Raphson
古いコメントを表示
Hello all,
In a script I'm trying to find roots of a function by Newton-Raphson method. In each iteration I'm finding and printing the relative approximation error.
What I want is, instead of printing them I would like plot my function and my relative approximation error in each iteration.
Any help is much appreciated.
My script file:
function [r] = newton(x1)
n = 1000;
tol_error = 0.001;
r = x1;
for t=1:n
x_plus = x1 - (my_func(x1)/my_func_diff(x1));
approx_error(t) = abs((x_plus - x1)/(x_plus))*100;
if (approx_error(t) < tol_error)
display(t);
display(approx_error(t));
r = x_plus;
return;
else
x1 = x_plus;
end
end
end
function y = my_func_diff(x)
y = 3*(x^2) - 20*x - 43;
end
function y = my_func(x)
y = x^3 - 10*(x^2) - 43*x + 52;
end
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で App Building についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!