Solve the following matrix equation G*x=b, reformulate as the unconstrained minimalization of a function

57 Views Asked by At

I need to write a matlab script, which will solve the following equation G*x=b where G is a sparse matrix, and b is a vector b = [1,2,1,2...]. Then I need to reformulate equivalently the problem as the unconstrained minimalization of the following quadratic function: $f(x) = $$\frac{1}{2}$$ x^T*G*x-b^T*x$

and implement the conjugate gradient algorithm for finding the minimum of $f(x)$ with exact directional minimalizaion.

I have to use a parfor loop. Does anyone have any idea how to to this and can push me in a right direction?

1

There are 1 best solutions below

0
On

To help you get started something important is indexing. Matrices are indexed like (rows,cols) in Matlab.

Assuming N is loop variable, ak is number of rows per in the loop. You can index matrices like this

A(1+ak*N:ak*(N+1),:)    % a block of ak rows and all columns of A

So for example

A(1+ak*2:ak*3,:) * b

will calculate partition nr 3 from above of the matrix-vector product $Ab$

Then inside the loop do multiplications like that and store results on their own positions. It may be better or worse to use cells instead and mat2cell.