MATLAB COMPILER RELEASE NOTES Guía de usuario Pagina 62

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 264
  • Tabla de contenidos
  • SOLUCIÓN DE PROBLEMAS
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 61
3 Getting Started with MEX-Files
3-4
The curve ca n be graphed in many ways. Sierpinski's method is:
Start with a triangle and from it remove a trianglethat is one-half the height
of the original and inverted. This leaves three triangles.
From each of the remaining three triangles, remove a triangle that is
one-fourth the height of these new triangles and inverted. This leaves nine
triangles.
The p rocess continues and at infinity the surface area becomes zero and t he
length of the curve is infinite.
gasket.m is a good candidate for compilation because it contains a loop. The
overhead ofthe
for loop command is relatively high compared to the cost of the
loop body. M-file programmers usually try to avoid loops containing scalar
operations because loops run relatively slowly under the MATLAB interpreter.
To achieve a reasonable approximation of the Sierpinski Gasket, set the
number of points to 50,000. To compute the coordinates and time the
computation, you can use
tic; x = gasket(50000); toc
To display the figure, you can use
imagesc(x); colormap([1 1 1;0 0 0]);
axis equal tight
Invoking the M-File
To get a bas eli ne read ing , yo u can determine how long it takes the MATLAB
interpreter to run
gasket.m. The built-in MATLAB functions tic and toc are
useful tools for measuring time.
tic; x = gasket(50000); toc
elapsed_time =
7.9620
On t he Pentium Pro 200, the M-file took about 10 seconds of CPU time to
calculate the first 50,000 points on the Sierpinski Gasket.
Vista de pagina 61
1 2 ... 57 58 59 60 61 62 63 64 65 66 67 ... 263 264

Comentarios a estos manuales

Sin comentarios