Linear fit through loglog plots.
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Kevin Osborn
am 1 Okt. 2021
Beantwortet: Kevin Osborn
am 1 Okt. 2021
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/756034/image.png)
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.
Akzeptierte Antwort
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Interpolation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!