九层妖塔 起于垒土
Matlab 李萨如图模拟_动态模拟李萨如图形形成过程保存为.GIF动图
一、数学分析
二、程序设计及使用说明
三、动图
四、代码
%此文件中的代码为M文件编程
close all;
clc;
clf;
axis([-1.5,1.5,-1.5,1.5])
axis manual
grid on
grid minor
title('李萨如图模拟')
xlabel('X轴')
ylabel('Y轴')
A=1;
B=1;
w=1;
Fx=0; %对定值提前赋值
t=linspace(0,4*pi,500); %定义t为0到4π有500个元素的行矩阵
mkdir 'C:\Users\Lenovo\Desktop\'/ 李萨如图形 %在桌面的绝对路径下新建文件夹
for c=1:54 %循环54次,生成54个图片
close all;
pause(3);
switch c
case 1
q=1;p=1;Fy=0; %选择变量值
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率1比1 %新建文件夹
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1'); %改变当前路径,保存旧路径
case 2
q=1;p=1;Fy=pi/4;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 3
q=1;p=1;Fy=pi/2;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 4
q=1;p=1;Fy=3*pi/4;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 5
q=1;p=1;Fy=pi;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 6
q=1;p=1;Fy=5*pi/4;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 7
q=1;p=1;Fy=3*pi/2;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 8
q=1;p=1;Fy=7*pi/4;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 9
q=1;p=1;Fy=2*pi;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率1比1');
case 10
q=2;p=1;Fy=0;
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率2比1
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 11
q=2;p=1;Fy=pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 12
q=2;p=1;Fy=pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 13
q=2;p=1;Fy=3*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 14
q=2;p=1;Fy=pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 15
q=2;p=1;Fy=5*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 16
q=2;p=1;Fy=3*pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 17
q=2;p=1;Fy=7*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 18
q=2;p=1;Fy=2*pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率2比1');
case 19
q=3;p=1;Fy=0;
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率3比1
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 20
q=3;p=1;Fy=pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 21
q=3;p=1;Fy=pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 22
q=3;p=1;Fy=3*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 23
q=3;p=1;Fy=pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 24
q=3;p=1;Fy=5*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 25
q=3;p=1;Fy=3*pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 26
q=3;p=1;Fy=7*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 27
q=3;p=1;Fy=2*pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比1');
case 28
q=3;p=2;Fy=0/q;
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率3比2
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 29
q=3;p=2;Fy=pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 30
q=3;p=2;Fy=pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 31
q=3;p=2;Fy=3*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 32
q=3;p=2;Fy=pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 33
q=3;p=2;Fy=5*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 34
q=3;p=2;Fy=3*pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 35
q=3;p=2;Fy=7*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 36
q=3;p=2;Fy=2*pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率3比2');
case 37
q=4;p=3;Fy=0/q;
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率4比3
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 38
q=4;p=3;Fy=pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 39
q=4;p=3;Fy=pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 40
q=4;p=3;Fy=3*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 41
q=4;p=3;Fy=pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 42
q=4;p=3;Fy=5*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 43
q=4;p=3;Fy=3*pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 44
q=4;p=3;Fy=7*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 45
q=4;p=3;Fy=2*pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率4比3');
case 46
q=5;p=3;Fy=0/q;
mkdir 'C:\Users\Lenovo\Desktop\李萨如图形\'/ 频率5比3
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 47
q=5;p=3;Fy=pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 48
q=5;p=3;Fy=pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 49
q=5;p=3;Fy=3*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 50
q=5;p=3;Fy=pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 51
q=5;p=3;Fy=5*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 52
q=5;p=3;Fy=3*pi/2/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 53
q=5;p=3;Fy=7*pi/4/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
case 54
q=5;p=3;Fy=2*pi/q;
oldFolder = cd('C:\Users\Lenovo\Desktop\李萨如图形\频率5比3');
end
for n=1:length(t)
plot(A*cos(Fx),B*cos(Fy),... %绘制起始点
'Color','green',...
'Marker','.',...
'linesty','-',...
'LineWidth',25,...
'MarkerFaceColor','green',...
'MarkerEdgeColor','green',...
'MarkerSize',25);
hold on
plot(A*cos(q*w*t(n)+Fx),B*cos(p*w*t(n)+Fy),... %绘制当前点
'Color','black',...
'Marker','^',...
'linesty','-',...
'LineWidth',1,...
'MarkerFaceColor','black',...
'MarkerEdgeColor','black',...
'MarkerSize',10);
axis([-1.5,1.5,-1.5,1.5])
axis manual
hold on
grid on
grid minor
title('李萨如图模拟')
xlabel('X轴')
ylabel('Y轴')
plot(A*cos(q*w*t(1:n)+Fx),B*cos(p*w*t(1:n)+Fy),... %绘制行进的曲线
'Color','red',...
'Marker','.',...
'linesty','-',...
'LineWidth',3.0,...
'MarkerFaceColor','red',...
'MarkerEdgeColor','red',...
'MarkerSize',1);
axis([-1.5,1.5,-1.5,1.5])
axis manual
grid on
grid minor
title('李萨如图模拟')
xlabel('X轴')
ylabel('Y轴')
hold off
axis manual
grid on
grid minor
frame=getframe(gcf); %捕获坐标区或图窗作为影片帧
imind=frame2im(frame);
[imind,cm] = rgb2ind(imind,256); %将 RGB 图像转换为索引图像
if n==1 %将图像写入图形文件
imwrite(imind,cm,'name.gif','gif', 'Loopcount',inf,'DelayTime',1e-4);
else
imwrite(imind,cm,'name.gif','gif','WriteMode','append','DelayTime',1e-4);
end
end
switch c %依次选择,将图片改名
case 1
movefile ('name.gif', '频率1比1 相位差0.gif') ;
case 2
movefile ('name.gif', '频率1比1 相位差45.gif') ;
case 3
movefile ('name.gif', '频率1比1 相位差90.gif') ;
case 4
movefile ('name.gif', '频率1比1 相位差135.gif') ;
case 5
movefile ('name.gif', '频率1比1 相位差180.gif') ;
case 6
movefile ('name.gif', '频率1比1 相位差225.gif') ;
case 7
movefile ('name.gif', '频率1比1 相位差270.gif') ;
case 8
movefile ('name.gif', '频率1比1 相位差315.gif') ;
case 9
movefile ('name.gif', '频率1比1 相位差360.gif') ;
case 10
movefile ('name.gif', '频率2比1 相位差0.gif') ;
case 11
movefile ('name.gif', '频率2比1 相位差45.gif') ;
case 12
movefile ('name.gif', '频率2比1 相位差90.gif') ;
case 13
movefile ('name.gif', '频率2比1 相位差135.gif') ;
case 14
movefile ('name.gif', '频率2比1 相位差180.gif') ;
case 15
movefile ('name.gif', '频率2比1 相位差225.gif') ;
case 16
movefile ('name.gif', '频率2比1 相位差270.gif') ;
case 17
movefile ('name.gif', '频率2比1 相位差315.gif') ;
case 18
movefile ('name.gif', '频率2比1 相位差360.gif') ;
case 19
movefile ('name.gif', '频率3比1 相位差0.gif') ;
case 20
movefile ('name.gif', '频率3比1 相位差45.gif') ;
case 21
movefile ('name.gif', '频率3比1 相位差90.gif') ;
case 22
movefile ('name.gif', '频率3比1 相位差135.gif') ;
case 23
movefile ('name.gif', '频率3比1 相位差180.gif') ;
case 24
movefile ('name.gif', '频率3比1 相位差225.gif') ;
case 25
movefile ('name.gif', '频率3比1 相位差270.gif') ;
case 26
movefile ('name.gif', '频率3比1 相位差315.gif') ;
case 27
movefile ('name.gif', '频率3比1 相位差360.gif') ;
case 28
movefile ('name.gif', '频率3比2 相位差0.gif') ;
case 29
movefile ('name.gif', '频率3比2 相位差45.gif') ;
case 30
movefile ('name.gif', '频率3比2 相位差90.gif') ;
case 31
movefile ('name.gif', '频率3比2 相位差135.gif') ;
case 32
movefile ('name.gif', '频率3比2 相位差180.gif') ;
case 33
movefile ('name.gif', '频率3比2 相位差225.gif') ;
case 34
movefile ('name.gif', '频率3比2 相位差270.gif') ;
case 35
movefile ('name.gif', '频率3比2 相位差315.gif') ;
case 36
movefile ('name.gif', '频率3比2 相位差360.gif') ;
case 37
movefile ('name.gif', '频率4比3 相位差0.gif') ;
case 38
movefile ('name.gif', '频率4比3 相位差45.gif') ;
case 39
movefile ('name.gif', '频率4比3 相位差90.gif') ;
case 40
movefile ('name.gif', '频率4比3 相位差135.gif') ;
case 41
movefile ('name.gif', '频率4比3 相位差180.gif') ;
case 42
movefile ('name.gif', '频率4比3 相位差225.gif') ;
case 43
movefile ('name.gif', '频率4比3 相位差270.gif') ;
case 44
movefile ('name.gif', '频率4比3 相位差315.gif') ;
case 45
movefile ('name.gif', '频率4比3 相位差360.gif') ;
case 46
movefile ('name.gif', '频率5比3 相位差0.gif') ;
case 47
movefile ('name.gif', '频率5比3 相位差45.gif') ;
case 48
movefile ('name.gif', '频率5比3 相位差90.gif') ;
case 49
movefile ('name.gif', '频率5比3 相位差135.gif') ;
case 50
movefile ('name.gif', '频率5比3 相位差180.gif') ;
case 51
movefile ('name.gif', '频率5比3 相位差225.gif') ;
case 52
movefile ('name.gif', '频率5比3 相位差270.gif') ;
case 53
movefile ('name.gif', '频率5比3 相位差315.gif') ;
case 54
movefile ('name.gif', '频率5比3 相位差360.gif') ;
end
end