Linear fit through loglog plots.
조회 수: 3 (최근 30일)
이전 댓글 표시
With the iteration data below find the best linear fit in the formula above and determine the slope, α (order of convergence), and the value of λ. How would I go about coding this in MatLab? I think I need to use loglog plots, but I'm not exactly sure how to go about this. I have used Newton's Method of approximation as shown below.
f = @(x) 2*exp(-2*x) + 4*sin(x) - 2*cos(2*x);
fp = @(x) 4*(-exp(-2*x) + sin(2*x) + cos(x));
x0 = 0.3;
N = 10;
tol = 1E-6;
x(1) = x0;
n = 2;
nfinal = N + 1;
while (n <= N + 1)
fe = f(x(n - 1));
fpe = fp(x(n - 1));
x(n) = x(n - 1) - fe/fpe;
if (abs(fe) <= tol)
nfinal = n;
break;
end
n = n + 1;
end
figure, plot(0:nfinal - 1,x(1:nfinal),'o-')
title('Newton''s Method')
xlabel('Iterations')
ylabel('Root Approximation')
table([1:length(x)]', x', 'VariableNames', {'Iteration' 'Root Approximation'})
x(n) = x(n - 1) - fe/fpe;
fprintf('Iteraion Root Approximation Tolerance Level\n')
fprintf('%3d: %20g %20g\n', n, x(n), abs(fe));
Thank you in advance for your help.
채택된 답변
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Biotech and Pharmaceutical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!