Finding a critical point for a function $f(x,y)$ using Newton Raphson method
Show older comments
I was tasked with finding the critical point of a function f(x,y)=(x-1)^2 + (y-1)^2
Using my Newton Raphson program written in MATLAB.
function [x0,y0] = NewtonMethod(f, g, a, b)
y0 = b;
x0 = a;
tol = 1e-18;
resf = tol + 1;
resg = tol + 1;
while resf > tol && resg > tol
dfdx = NPderiv(f, x0, y0, 1); %function which calculates the partial derivative
dfdy = NPderiv(f, x0, y0, 2);
dgdx = NPderiv(g, x0, y0, 1);
dgdy = NPderiv(g, x0, y0, 2);
jf1 = [f(x0,y0) dfdy; ...
g(x0,y0) dgdy];
jg1 = [dfdx f(x0,y0); ...
dgdx g(x0,y0)];
j2 = [dfdx dfdy; ...
dgdx dgdy];
jx = det(jf1)./det(j2);
jy = det(jg1)./det(j2);
x0 = x0 - jx;
y0 = y0 - jy;
resf = abs(f(x0,y0));
resg = abs(g(x0,y0));
end
end
y0 = b;
x0 = a;
tol = 1e-18;
resf = tol + 1;
resg = tol + 1;
while resf > tol && resg > tol
dfdx = MyNPderiv(f, x0, y0, 1);
dfdy = MyNPderiv(f, x0, y0, 2);
dgdx = MyNPderiv(g, x0, y0, 1);
dgdy = MyNPderiv(g, x0, y0, 2);
jf1 = [f(x0,y0) dfdy; ...
g(x0,y0) dgdy];
jg1 = [dfdx f(x0,y0); ...
dgdx g(x0,y0)];
j2 = [dfdx dfdy; ...
dgdx dgdy];
jx = det(jf1)./det(j2);
jy = det(jg1)./det(j2);
x0 = x0 - jx;
y0 = y0 - jy;
resf = abs(f(x0,y0));
resg = abs(g(x0,y0));
end
end
My quandary is however how I should treat my second input variable "g", since they want me to use this specific code to find the critical point of $f(x,y)=(x-1)^2 + (y-1)^2$
My idea was to replace g with the linearization of f since
L(x,y) is approximately f(x,y)
Any ideas?
Answers (0)
Categories
Find more on Newton-Raphson Method in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!