No BSD License  

Highlights from
Simple example how to create a mex-file!

1.66667

1.7 | 4 ratings Rate this file 4 Downloads (last 30 days) File Size: 10.07 KB File ID: #13920

Simple example how to create a mex-file!

by Giovani Tonel

 

10 Feb 2007 (Updated 12 Dec 2007)

Example how to create a mex-file (.dll)

| Watch this File

File Information
Description

Simple example how to create a mex-file (.dll), where the function tridi.m ( it solves linear systems -tridiagonal matrix) was compiled to the file named tridi.dll.

MATLAB release MATLAB 5.3.1 (R11.1)
Other requirements lcc compiler
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (5)
13 Feb 2007 Zhijun Wang

Your MATLAB version has been out of data, there are many differences in the new MATLAB version!

28 Feb 2007 hamed nozari  
11 Dec 2007 Tim Davis

This is a very poor example. The tridi.dll file was created from a C file that was generated from the MATLAB Compiler. It's useless for later versions of MATLAB of course, but the C code is fortunately provided.

However, the C code (tridi.c) is automatically generated from tridi.m by the MATLAB compiler. As such, the tridi.c code is ugly and completely unreadable. You would never want to read tridi.c; consider it a "binary" file as far as readability is concerned. It does not demonstrate how to write C code that MATLAB can call.

The dif_finitas_tridi.m code is a test code for the package, and has comments written mostly in Portugese (I think). That's fine; it's useful to have some international codes. However, even in Portugese the code is poorly commented and very poorly structured. The code is a mess. Some of the comments are in English, so it is very inconsistent.

It has a function called func.m which has no comments describing what it does. The name is about as generic as it comes.

The run_tridi.m file says this is an example of how to create a mex-file. It isn't; it is an example of how to compile an ugly C code that is the output of the MATLAB Compiler. You would *never* use this to write a clean mex file on your own.

Finally, we are left wth the only decent code in the entire package: tridi.m. It solves an unsymmetric tridiagonal linear system. It contains an annoying message "Solving linear system..." that is printed each time you call it.

If you delete that, the function is reasonably well documented and performs reasonably well (it's only twice as slow as x=A\b in MATLAB 7.5).

Thus, it's only purpose is to illustrate a method for solving tridiagonal systems ... without pivoting (if given matrices that do not require pivoting, it is accurate, otherwise it fails terribly as compared with x=A\b).

This file is not a useful example of how to use mex, as it claims to be. If that were all it contained, I would give it a rating of 1.

It has a decent tridiagonal solver function which is useful not for serious use but to read the code and understand the algorithm (with no pivoting).

As an example of using MEX, ignore this file; it is worse than useless since it confuses you and suggests methods that one should never use in writing your own MEX file.

The code is misfiled under "Control systems and modelling -> Simulation models". It has nothing to do with that except for the poorly written test code which generates the tridiagonal system.

11 Dec 2007 Tim Davis

Oops. I meant to give it a rating of a 2, not 1. It "needs improvement", namely, delete everything except tridi.m, and remove the "disp" commands from that function. Next, state that the function is not meant for speed, but just to illustrate an algorithm.

I am "fixing" my misrating of a 1 in my last review by rating it 3 here, to get an average rating of 2. Sorry for the confusion.

11 Dec 2007 Tim Davis

MATLAB R12 includes a function tridi.m in Version 1.2 of the MATLAB Compiler. I found that in the MATLAB Compiler documentation, but I don't have access to the file. tridi.m is described there as:

"tridi.m M-file to solve a tridiagonal system of equations. Compile tridi.m into a MEX-file."

Is it the same one that is included here? I think it is, because the tridi.m file has a CVS stamp, $Revision: 1.1$ on it. Note that The MathWorks copyright has been removed from the file (or perhaps it never existed).

The tridi.m file states that it was "Modified by Giovani Tonel" but doesn't state who originally authored the code.

If tridi.m is straight from the MATLAB Compiler examples, and if The Mathworks copyright has been stripped ... then what is this doing here, at all?

Please login to add a comment or rating.
Updates
21 May 2007

I've added some words here!

12 Dec 2007

I added some words!!!!

Tag Activity for this File
Tag Applied By Date/Time
simulation Giovani Tonel 22 Oct 2008 09:00:16
mexfiles Giovani Tonel 22 Oct 2008 09:00:16
dll Giovani Tonel 22 Oct 2008 09:00:16
tridiagonal matrix Giovani Tonel 22 Oct 2008 09:00:16

Contact us at files@mathworks.com