Problem Set 7TATATATA

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

NAME: DENMARK C.

TABASAN

1.

Use Code
% Define the matrix A and vector b
A = [5, 4, 1, 1; 4, 5, 1, 1; 1, 1, 4, 2; 1, 1, 2, 4];
b = [1; 2; 3; 4];

% Solve the equation using pcg


x = pcg(A, b);

% Calculate the residual norm


residual = norm(b - A*x);

% Display the solution and the residual norm


disp('Solution:');
disp(x);
disp(['Residual Norm: ', num2str(residual)]);
MATLAB INPUT

Data 1.1 MATLAB script input


(See Data 1.1) The code solves a linear system of equations using the pcg function. The system is
defined by the matrix A and vector b. The pcg function uses the preconditioned conjugate gradient
method to iteratively solve the system and find the solution vector x. After obtaining the solution,
the code calculates the residual norm, which measures the discrepancy between the original
equation (b - A*x) and the computed solution. The residual norm quantifies the accuracy of the
solution. The code then displays the solution vector x and the computed residual norm.

Data 1.2 MATLAB Workspace input


Data 1.3 MATLAB Results

(See Data 1.3) The code successfully applies the pcg function to solve a linear system of equations.
It converges at the fourth iteration to a solution with a relative residual of 1.3e-15, indicating high
accuracy. The solution vector is displayed, showing the values for each variable in the system.
Additionally, the residual norm is calculated and found to be 7.351e-15, further confirming the
accuracy of the solution.

Use Code
% Define the objective function
fun = @(xy) (2*xy(1) - sin((xy(1) + xy(2))/2))^2 + (2*xy(2) - cos((xy(1) - xy(2))/2))^2;

% Define the starting point


x0 = [10; -10];
% Call the minscg function
[x, z] = minscg(fun, x0);

% Display the solution


disp('Solution:');
disp(x);
disp(['Minimum value: ', num2str(z)]);

MATLAB INPUT

Data 2.1 MATLAB script input

(See Data 2.1) The code applies the minscg function to minimize the objective function. The
objective function is defined as a mathematical expression involving two variables (x and y). The
code specifies the starting point (x0) for the optimization. The minscg function utilizes the scaled
conjugate gradient method to iteratively minimize the objective function and find the solution. The
resulting solution vector (x) and the corresponding minimum value (z) of the function are then
displayed.
Data 2.2 MATLAB Workspace input

Data 2.3 MATLAB Results


(See Data 2.3) The minscg function successfully applies the scaled conjugate gradient method to
minimize the objective function. The optimization process iterates through several steps, gradually
reducing the function value and approaching a local minimum. The algorithm converges at the
11th iteration, finding a local minimum. The solution vector (x) is displayed, indicating the values
of the variables that minimize the objective function. Additionally, the minimum value of the
objective function is reported as 2.6757e-13, which represents the smallest value achieved during
the optimization process.

You might also like