CS代考计算机代写 matlab %

%
% Exercise 2:
%
% Consider the following LP:
%
% min x_1 + 3 x_2
% s.t. x_1 + x_2 = 1
% x_i >= 0, i = 1, 2.
%
% Formulate the first order optimality condition for the barrier problem:
%
% x_1 + x_2 = 1
% y + s_1 = 1
% y + s_2 = 3
% x_1 * s_1 = Mu
% x_2 * s_2 = Mu.
%
% Solve this system of nonlinear equations for several values of Mu:
% Mu = 10.0, Mu = 1.0, Mu = 0.1, Mu = 0.01.
%
% Use the following MATLAB routine.

Mu = 10.0;
x = [1.0, 1.0]’;
y = 1;
s = [1.0, 1.0]’;
iter = 0;
maxiter = 6;

while (iter < maxiter) iter = iter+1; Jacobian_f = [ 1.0, 1.0, 0.0, 0.0, 0.0; 0.0, 0.0, 1.0, 1.0, 0.0; 0.0, 0.0, 1.0, 0.0, 1.0; s(1), 0.0, 0.0, x(1), 0.0; 0.0, s(2), 0.0, 0.0, x(2)]; NewtonRHS = [x(1) + x(2) - 1.0; y + s(1) - 1.0; y + s(2) - 3.0; x(1) * s(1) - Mu; x(2) * s(2) - Mu]; %Add commands to compute the Newton direction as the solution of the %Newton equations and use it to update the vectors x, y and s fprintf('Newton Method Iteration %4d: ', iter); fprintf('x= %10.4e, %10.4e, y= %10.4e, s= %10.4e, %10.4e\n', x, y, s); end % while (iter < maxiter)