No BSD License  

Highlights from
matrixop

4.33333

4.3 | 3 ratings Rate this file 13 Downloads (last 30 days) File Size: 66.1 KB File ID: #14137

matrixop

by

 

02 Mar 2007 (Updated )

A Matlab object that acts just like a matrix but represents a linear operator as a function.

| Watch this File

File Information
Description

Many of the iterative methods in Matlab are designed to work with either a function handle to provide A*x, or a matrix A directly. Developing code for each paradigm is a pain. The matrixop class yields the flexibility of Matlab syntax using function handles or anonymous functions.

n = 100;
A = spdiags([e -2*e e], -1:1, n, n);
Afun = @(x) [-2*x(1) + x(2); x(1:n-2) - 2*x(2:n-1) + x(3:n); x(n-1)-2*x(n)];
op = matrixop(A);
x = linspace(-1,1,n)';
b = op*x; % calls Afun(x)
xminres = minres(op,b,[],200); % runs minres on op where op*x = Afun(x)
xgmres = gmres(op,b,[], [],200);

The advantage of the matrixop class is that you can write a single code that works for either a Matlab matrix or a function handle/linear operator representation. This simplifies the code and eliminates syntactic juggling that can cause bugs.

The zip file includes numerous examples of how to use the matrixop class along with a sample showing the performance implications. See the demo directory.

MATLAB release MATLAB 7 (R14)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (4)
08 Jul 2008 Adnan Abdulally

this would be great if i could actually implement it in matlab

17 Dec 2007 vivekanand b

how to implement it

03 Mar 2007 Haomin Zhang

wonderful

02 Mar 2007 John D'Errico

A creative, interesting idea. Good examples. Good help.

Contact us