I want to optimize a problem using Newton's Method in MATLAB, however, I am not getting a correct answer. I am hoping someone could me with my codes. The answer should be around 33.333 but I am getting 25.
clc; clear all; close all;
f = @(x) (5*sqrt(2))*(50-x)*(sqrt(2*x-50)); %Objective Function
df1 = @(x) - 10*(x - 25)^(1/2) - (5*(x - 50))/(x - 25)^(1/2); % First Derivative
df2 = @(x) (5*(x - 50))/(2*(x - 25)^(3/2)) - 10/(x - 25)^(1/2); % Second Derivative
K = 200;
x = 0;
Err = 0.0001;
for i = 1:K
x = x - f(x)/df1(x);
j = i + 1;
xx(j) = x;
err = abs(xx(j)-xx(j-1));
if err < Err
break
end
z(i) = x;
end
x