1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Matlab Cg algorithm

  1. Dec 27, 2008 #1
    1. The problem statement, all variables and given/known data
    [​IMG]


    2. Relevant equations

    The code
    Code (Text):

    u = [ 0 ;zeros(n-2,1); 0]; % this has to be zero.
    k = 0;
    r = b;

    %algoritme
    while k<100
        z=inv(M)*r;
        k = k+1
       
        if k==1
            p = z;
            r_1 = b;
            z_1 = z;
               
        else
            beta = (r_1'*z_1)/(r_2'*z_2);
            p = z_1+ beta*p;
        end
       
        alpha = (r_1'*z_1)/(p'*A*p);
        u = u + alpha*p;
        r= r_1-alpha*A*p;

    r_2 = r_1;
    r_1 = r;

    z_2 = z_1;
    z_1 = z;

    end
     

    3. The attempt at a solution
    Somewhere is a mistake in the code (aside the fact that A and b aren't shown), because it doesn't converge. But I can't find it. Can someone help me?
     
    Last edited: Dec 27, 2008
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you help with the solution or looking for help too?



Similar Discussions: Matlab Cg algorithm
Loading...