0% found this document useful (0 votes)
24 views

% Tebakan Awal: Function

The document describes an iterative numerical method for finding the solution to a system of nonlinear equations. It defines an initial guess for x and y, calculates the Jacobian and gradient, then uses Cramer's rule to determine the step direction and update x and y until the error is below a tolerance. It provides the function definitions for calculating F and its components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

% Tebakan Awal: Function

The document describes an iterative numerical method for finding the solution to a system of nonlinear equations. It defines an initial guess for x and y, calculates the Jacobian and gradient, then uses Cramer's rule to determine the step direction and update x and y until the error is below a tolerance. It provides the function definitions for calculating F and its components.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

function contohtgs11

clc; clear
% Tebakan awal
xold = 1.5;
yold = 3.5;
eps = 1e-3;
tol = 1;
er = 10;

while er>tol
% Hitung dan susun F dan J
F = fungsi(xold,yold);
F = -F;

J = zeros(2);
fmin = fungsi(xold-eps,yold);
fplus = fungsi(xold+eps,yold);
J(:,1) = (fplus - fmin)/2/eps;
fmin = fungsi(xold,yold-eps);
fplus = fungsi(xold,yold+eps);
J(:,2) = (fplus - fmin)/2/eps;

% Hitung d dengan Cramer's rule


d = zeros(2,1);
d(1) = (F(1)*J(2,2) - F(2)*J(1,2))/(J(1,1)*J(2,2) - J(2,1)*J(1,2));
d(2) = (J(1,1)*F(2)-J(2,1)*F(1))/(J(1,1)*J(2,2) - J(2,1)*J(1,2));

% Hitung xnew dan ynew


xnew = xold+d(1);
ynew = yold+d(2);

% Hitung error
erx = abs((xnew-xold)/xnew)*100;
ery = abs((ynew-yold)/ynew)*100;

if erx >ery
er = erx;
else
er = ery;
end
xold = xnew;
yold = ynew;
end

[xnew; ynew]

function Fi = fungsi(xi,yi)
Fi = zeros(2,1);
Fi(1) = xi^2 + xi*yi - 10;
Fi(2) = yi + 3*xi*yi^2 - 57;
end

1
end

ans =

2.0000
3.0000

Published with MATLAB® 7.13

You might also like