Effacer les filtres
Effacer les filtres

Newton's Method Convergence Plot

1 vue (au cours des 30 derniers jours)
Zyruss Edjan
Zyruss Edjan le 17 Oct 2019
Im currently trying to creat a convergence plot for my Newton's Method code. But I keep on getting a function error message that says Index exceeds the numbers of elements. I'm not really sure how to fix it.
function x_root = newtonze(x_est, tol, max_iter)
w = 20*10^3; L = 4; E = 70*10^9; I = 52.9*10^(-6);
for i = 1:max_iter
Xi = x_est - ((w*(7*L^4 - 30*L^2*x_est^2 + 15*x_est^4))/(360*E*I*L))/(-(w*x_est*(L^2 - x_est^2))/(6*E*I*L));
if abs((Xi-x_est)/x_est) < tol
x_root = Xi;
break
end
x_est=Xi;
end
x_root=x_est;
hold on
% Plot evolution of the solution
figure('Color','White')
plot(0:max_iter-1,x_root(1:max_iter),'o-')
title('Newton''s Method Solution: $f(x) = x + x^{\frac{4}{3}}$','FontSize',20,'Interpreter','latex')
xlabel('Iteration','FontSize',16)
ylabel('$x$','FontSize',16,'Interpreter','latex')
end

Réponses (1)

Sid Singh
Sid Singh le 21 Oct 2019
Hi, you are trying to plot a scalar value "x_root" against a time series which is why you are getting the error. Create an array
x_root = zeros(1, max_iter);
for i = 1:max_iter
Xi = x_est - ((w*(7*L^4 - 30*L^2*x_est^2 + 15*x_est^4))/(360*E*I*L))/(-(w*x_est*(L^2 - x_est^2))/(6*E*I*L));
if abs((Xi-x_est)/x_est) < tol
x_root(i) = Xi;
break
end
x_est=Xi;
end
and store values in that array. You would get zeros in the plot where this
if abs((Xi-x_est)/x_est) < tol
condition is not being met.

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by