Code covered by the BSD License  

Highlights from
Conjugate Gradient Method

5.0

5.0 | 2 ratings Rate this file 83 Downloads (last 30 days) File Size: 1.44 KB File ID: #22494

Conjugate Gradient Method

by Yi Cao

 

18 Dec 2008 (Updated 22 Dec 2008)

Conjugate Gradient Method to solve a system of linear equations

| Watch this File

File Information
Description

The conjugate gradient method aims to solve a system of linear equations, Ax=b, where A is symmetric, without calculation of the inverse of A. It only requires a very small amount of membory, hence is particularly suitable for large scale systems.

It is faster than other approach such as Gaussian elimination if A is well-conditioned. For example,

n=1000;
[U,S,V]=svd(randn(n));
s=diag(S);
A=U*diag(s+max(s))*U'; % to make A symmetric, well-contioned
b=randn(1000,1);
tic,x=conjgrad(A,b);toc
tic,x1=A\b;toc
norm(x-x1)
norm(x-A*b)

Conjugate gradient is about two to three times faster than A\b, which uses the Gaissian elimination.

MATLAB release MATLAB 7.7 (R2008b)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (4)
04 Jan 2009 Luigi Giaccari

A\b uses cholesky factorization if A is simmetric. It swithes to gauss method when A is not simmetric and the factorization fails due to negative sqrt input.

I don't know if it is present in all version, but there already is a conjgrad method in matlab.

Try:
 
help pcg

Anyway thank to Cao, submissions that works are always usefull, in the worst case you can study the algorithm.

 

13 Jan 2009 Lei

Could anybody tell me how to evaluate the time required by the SVD. Please kindly note the svd.m called directly by the workspace is a built-in function, which is much faster than the svd.m available on the Matlab website. So which one is more suitable to evaluate the required time?

Actually, I am trying to compare a new algorithm with the SVD in computational cost or time. I suppose the built-in SVD function might be faster than the source-code SVD function. Could anybody help me? Thanks a lot for your kindly helps in advance! My email address is huanglei8rsp@yahoo.com.cn.

05 Apr 2009 V. Poor  
02 Feb 2012 Kovács Sebestyén

great.thanks

Please login to add a comment or rating.
Updates
22 Dec 2008

update description

Tag Activity for this File
Tag Applied By Date/Time
mathematics Yi Cao 19 Dec 2008 12:45:12
linear algebra Yi Cao 19 Dec 2008 12:45:12
optimization Yi Cao 19 Dec 2008 12:45:12
linear equation Yi Cao 19 Dec 2008 12:45:12
linear algebra pradeep kumar 09 Nov 2010 05:38:10

Contact us at files@mathworks.com