Question: % Define the functions representing the equations f 1 = @ ( x , y ) - x ^ 2 + x + 0 .

% Define the functions representing the equations
f1= @(x, y)-x^2+ x +0.75- y;
f2= @(x, y) y +5*x*y - x^2;
% Define the partial derivatives of the functions with respect to x and y
df1_dx = @(x, y)-2*x +1;
df1_dy = @(x, y)-1;
df2_dx = @(x, y)-2*x +5*y;
df2_dy = @(x, y)1+5*x;
% Initial guesses
x0=1.2;
y0=1.2;
% Set tolerance and maximum number of iterations
tolerance =1e-6;
maxIterations =100;
% Initialize variables
x = x0;
y = y0;
iteration =0;
while iteration < maxIterations
% Evaluate the functions and their derivatives at the current point
f1_val = f1(x, y);
f2_val = f2(x, y);
J =[df1_dx(x, y), df1_dy(x, y); df2_dx(x, y), df2_dy(x, y)];
% Calculate the update using the Newton-Raphson formula
update =-J \[f1_val; f2_val];
% Update x and y
x = x + update(1);
y = y + update(2);
% Check for convergence
if norm(update)< tolerance
fprintf('Converged after %d iterations.
', iteration);
fprintf('Solution: x =%.6f, y =%.6f
', x, y);
break;
end
iteration = iteration +1;
end
if iteration >= maxIterations
fprintf('Newton-Raphson did not converge after %d iterations.
', maxIterations);
end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!