PPAGAF NR

Version 1.0.0 (75.6 KB) by Abhishek
UNULIOYLOI
0 Downloads
Updated 25 Jun 2024

View License

clc
% NEWTON RAPHSON
syms x1
syms x2
syms x3
f1 = 3*x1 - cos(x2*x3) - 0.5;
f2 = x1*x1 - 81*(x2 + 0.1)^2 + sin(x3) + 1.06;
f3 = exp(x1*x2) + 20*x3 + (10*pi - 3)/3;
% Jacobian Matrix
Df = jacobian([f1; f2; f3], [x1, x2, x3]);
% Initial guess
Xr = [0.11, 0.5, -0.123]';
tolerance = 1e-6; % Tolerance level for convergence
maxIterations = 100; % Maximum number of iterations
% Arrays to store values for plotting
x1_values = [];
x2_values = [];
x3_values = [];
% Iterations
iteration = 0;
error = inf;
while error > tolerance
F = double(subs([f1; f2; f3], [x1, x2, x3], Xr'));
J = double(subs(Df, [x1, x2, x3], Xr'));
deltaX = -J\F;
XrNew = Xr + deltaX;
error = norm(XrNew - Xr);
Xr = XrNew;
iteration = iteration + 1;
% Store values for plotting
x1_values(iteration) = Xr(1);
x2_values(iteration) = Xr(2);
x3_values(iteration) = Xr(3);
end
% Plotting
iterations = 1:iteration;
figure;
subplot(3, 1, 1);
plot(iterations, x1_values, 'r-');
xlabel('Iteration');
ylabel('x1 Value');
title('Iterations vs x1 Values');
grid on;
subplot(3, 1, 2);
plot(iterations, x2_values, 'g-');
xlabel('Iteration');
ylabel('x2 Value');
title('Iterations vs x2 Values');
grid on;
subplot(3, 1, 3);
plot(iterations, x3_values, 'b-');
xlabel('Iteration');
ylabel('x3 Value');
title('Iterations vs x3 Values');
grid on;

Cite As

Abhishek (2025). PPAGAF NR (https://www.mathworks.com/matlabcentral/fileexchange/168821-ppagaf-nr), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2024a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0