MATLAB Compiler    

A Simple Example -- The Sierpinski Gasket

Consider an M-file function called gasket.m:

How the Function Works

This function determines the coordinates of a Sierpinski Gasket using an Iterated Function System algorithm. The function starts with three points that define a triangle, and starting at one of these points, chooses one of the remaining points at random. A dot is placed at the midpoint of these two points. From the new point, a dot is placed at the midpoint between the new point and a point randomly selected from the original points. This process continues and eventually leads to an approximation of a curve.

The curve can be graphed in many ways. Sierpinski's method is

To achieve a reasonable approximation of the Sierpinski Gasket, set the number of points to 50,000. To invoke the M-file and compute the coordinates, you can use

To display the figure, you can use


  Working with MEX-Files Compiling the M-File into a MEX-File