Newton's Method Convergence Plot
조회 수: 1 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
답변 (1개)
Sid Singh
2019년 10월 21일
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.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Function Creation에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!