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?
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
So for example
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.