Labfans是一个针对大学生、工程师和科研工作者的技术社区。 论坛首页 | 联系我们(Contact Us)
MATLAB爱好者论坛-LabFans.com
返回   MATLAB爱好者论坛-LabFans.com > 其它 > 资料存档 > MATLAB技术文章
MATLAB技术文章 MATLAB Technical Articles From Mathworks
 
 
主题工具 显示模式
旧 2022-10-18, 07:25   #1
poster
高级会员
 
注册日期: 2019-11-21
帖子: 3,006
声望力: 66
poster 正向着好的方向发展
默认 modfun, A Short Program Produces Impressive Graphics - Cleve Moler on Mathematics and Computing

This nifty graphics gem started with a contribution by Paul Villain to the MATLAB 2022 Mini Hack, currently taking place on MATLAB Central.

Contents
modfun

Villain's contribution is 102 mod 500 . My rewrite is modfun. Villain's 102 and 500 become the parameters m and n.

modfun(m,n) connects n points, z(j), equally spaced around the complex unit circle, by n+1 straight lines. The j-th line connects z(j+1) to z(mod(j*m,n)+1).code

The basic code uses complex arithmetic and is only eight lines long. When the graphics is done with line instead of plot, it is not necessary to use hold on.

function modfun(m,n) init_fig z = exp(2i*pi*(0:n)/n); for j = 0:n zj = [z(j+1),z(mod(j*m,n)+1)]; line(real(zj),imag(zj)) end endThe initialization makes line possible.

function init_fig axis([-1 1 -1 1]) axis square axis off endAnimation

This animation of modfun(105,200) has one frame for every five lines.



Gallery

A sample.





Quiz

Match these calls to modfun to the plots in the Gallery.

modfun(88,179) modfun(89,220) modfun(99,200) modfun(101,200) modfun(111,200) modfun(113,188) modfun(126,188) modfun(126,200)

Get the MATLAB code (requires JavaScript)

Published with MATLAB® R2022a




More...
poster 当前离线   回复时引用此帖
 


发帖规则
不可以发表新主题
不可以发表回复
不可以上传附件
不可以编辑自己的帖子

启用 BB 代码
论坛启用 表情符号
论坛启用 [IMG] 代码
论坛启用 HTML 代码



所有时间均为北京时间。现在的时间是 02:53


Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.