Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Can someone help with #2? This is NOT homework. This was a website for Fall 2011, but it is a very interesting question and I would greatly appreciate help


share|cite|improve this question
What have you tried so far? What exactly is the problem you are facing? Give us some hints. – k1next Jan 31 '13 at 10:49
I really need help in starting it. Can you please provide a solution? Thanks – Buddy Holly Feb 1 '13 at 1:16
Do you know how CG works ? – k1next Feb 1 '13 at 6:03
I do, its a bunch of formulas. Can you please provide solution to this? – Buddy Holly Feb 1 '13 at 7:54
up vote 2 down vote accepted

We can use the CG algorithm, presented e.g. here at Wikipedia.

function [x] = conjgrad(A,b,x)

    for i=1:10000000
        if sqrt(rsnew)<0.05 
            disp(i)          % Note: I added this to see the number of Iteration

We then have to set up our matrices as described in the pdf, lets also call it $A$. We have $b$ as our right hande side and need a startvector $x$. For $x$ I simply took $x=rand(size(b))$, so just a random vector of the same size as $b$. Running the code, we can see that it takes 7 Iteration.

For b) you should take a look at this. You have to modify the code above. Then c) is just playing with your code. It would be nice if you provide Information on what you tried. Also instead of calling CG "a bunch of formulas" you could simply understand and apply these formulas.

share|cite|improve this answer
Thanks, but I was interested in a hand computational solution. Can you please illustrate it for this case problem and work out a few by hand? – Buddy Holly Feb 1 '13 at 9:15
Above comment was for part a. For part b, can you also elaborate by hand. Thanks!! – Buddy Holly Feb 1 '13 at 9:16
Well you can simply do the code "by hand". Just move from line to line and see what you have to do. – k1next Feb 1 '13 at 9:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.