母亲节到了,从我们出生开始,她们就辛苦地哺育我们成长:从喂奶换尿布到生病时不眠不休地照料,含辛茹苦赚钱供我们读书,省吃俭用也要把最好的给我们。就算现在我们毕业了、有了自己的家庭,她们还是不会停止对我们的牵挂。她们,就是我们伟大的母亲。
今天5月8日是母亲节,在这样一个特殊日子里,让我们一起,跟随着模小数,用MATLAB编程画一颗感恩的心,送给我们伟大的母亲吧!
MATLAB源程序代码一
x =-1.15:0.001:1.15;
y1 =1/2*(x.^2.^(1/3)+(x.^4.^(1/3)-4*x.^2+4).^(1/2));
y2 =1/2*(x.^2.^(1/3)-(x.^4.^(1/3)-4*x.^2+4).^(1/2));
figure
hold on
plot(x,y1,'.r');
plot(x,y2,'.r');
效果图
clc,clear,closeall
[x,y,z]=meshgrid(linspace(-1.3,1.3));
val=(x.^2+(9/4)*y.^2+z.^2-1).^3-x.^2.*z.^3-(9/80)*y.^2.*z.^3;
isosurface(x,y,z,val,0)
axis equal
view(-10,24)
colormap flag
camlight
lighting phong
效果图
MATLAB源程序代码三
b=0:0.01*pi:2*pi;
a=2;
r=a*(1-sin(b));
h=polar(b,r,'r');
set(h,'LineWidth',6);
效果图
MATLAB源程序代码四
a=ezplot('17*x^2-16*abs(x)*y+17*y^2-225');
set(a,'color','r','LineWidth',6);
效果图
MATLAB源程序代码五
[x,y]=meshgrid(-5:0.01:5,-5:0.01:5);
v=17*x.^2-16*abs(x).*y+17*y.^2+150./abs(5*x+sin(5*y))<225;
contourf(x,y,v);
colormap(jet);
效果图
MATLAB源程序代码六
[X,Y,Z] =meshgrid(linspace(-3,3,101));
F =-X.^2.*Z.^3-(9/80).*Y.^2.*Z.^3+(X.^2+(9/4).*Y.^2+Z.^2-1).^3;
hFigure =figure;
sz =get(hFigure, 'Position');
set(hFigure,'Position',[sz(1)-0.15*sz(3) sz(2) 1.3*sz(3) sz(4)]);
set(hFigure,'color','w','menu','none')
hAxes =axes('Parent',hFigure,'NextPlot','add','DataAspectRatio',[11 1], 'XLim',[30120],'YLim',[3565],'ZLim',[3075]);
view([-3930]);
axis off
hidden on
p =patch(isosurface(F,-0.001));
set(p,'FaceColor','w','EdgeColor','none');
foriX = [35 38 41 45 48 51 54 57 61 64 67]
plane =reshape(F(:,iX,:),101,101);
cData =contourc(plane,[0 0]);
xData =iX.*ones(1,cData(2,1));
h3=plot3(hAxes,xData,cData(2,2:end),cData(1,2:end),'k');
set(h3,'color','r');
pause(.1),drawnow
end
foriY = [41 44 47 51 55 58 61]
plane =reshape(F(iY,:,:),101,101);
cData =contourc(plane,[0 0]);
yData =iY.*ones(1,cData(2,1));
h4=plot3(hAxes,cData(2,2:end),yData,cData(1,2:end),'k');
set(h4,'color','r');
pause(.1),drawnow
end
foriZ = [36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 69 71]
plane =F(:,:,iZ);
cData =contourc(plane,[0 0]);
startIndex= 1;
ifsize(cData,2) > (cData(2,1)+1)
startIndex= cData(2,1)+2;
zData= iZ.*ones(1,cData(2,1));
h0=plot3(hAxes,cData(1,2:(startIndex-1)),cData(2,2:(startIndex-1)),zData,'k');
set(h0,'color','r');
end
zData =iZ.*ones(1,cData(2,startIndex));
h1=plot3(hAxes,cData(1,(startIndex+1):end),cData(2,(startIndex+1):end),zData,'k');
set(h1,'color','r');
pause(.1),drawnow
end
pause(.2)
text(7,50,70,'I','color','r','fontWeight','bold','FontAngle','italic','fontsize',100)
pause(.5)
text(80,50,43,'YOU','color','r','fontWeight','bold','FontAngle','italic','fontsize',100)
pause(.2)
line([2080],[50 50],[52.5 52.5], 'color','k')
line([5050],[20 80],[52.5 52.5], 'color','k')
line([5050],[50 50],[30 80], 'color','k')
text(20,50,50,'x')
text(48,20,50,'y')
text(45,50,80,'z')
text(30,60,30,'(x^2+9/4y^2+z^2-1)^3- x^2z^3-9/80y^2z^3=0','fontsize',8)
text(35,45,30,'-3<3','fontsize',8)
效果图
MATLAB源程序代码七
f=@(x,y,z)(x.^2+(9./4).*y.^2 + z.^2 - 1).^3 - x.^2.*z.^3 - (9./80).*y.^2.*z.^3;
[x,y,z]=meshgrid(linspace(-3,3));
val=f(x,y,z);
[p,v]=isosurface(x,y,z,val,0);
patch('faces',p,'vertices',v,'facevertexcdata',jet(size(v,1)),'facecolor','w','edgecolor','flat');
view(3);
grid on;
axis equal;
效果图
大家觉得哪一颗感恩的心最好看呢?
另外,大家可以思考一下:上述图像中,哪一个使用了极坐标,哪一个使用了隐函数,哪一个使用了动画编程,哪一个使用了网格化?
最后,请写出每一颗感恩的心的数学函数表达式哦!
Python源程序代码八
import matplotlib.pyplot as plt
import matplotlib.patches aspatches
rects = [
(137,65,34,4,(124,30,31)),(167,69,16,4,(124,30,31)),(133,98,21,4,(124,30,31)),
(150,94,17,4,(124,30,31)),(162,89,5,5,(124,30,31)),(167,85,12,5,(124,30,31)),
(167,98,16,4,(124,30,31)),(179,90,4,8,(124,30,31)),(183,90,13,4,(124,30,31)),
(192,82,4,8,(124,30,31)),(184,82,8,3,(124,30,31)),(167,77,21,5,(124,30,31)),
(171,73,4,4,(124,30,31)),(179,73,4,4,(124,30,31)),(175,82,4,3,(124,30,31)),
(133,69,4,13,(124,30,31)),(125,82,4,12,(124,30,31)),(129,90,21,4,(124,30,31)),
(133,94,4,4,(124,30,31)),(129,77,4,9,(124,30,31)),(142,82,8,4,(124,30,31)),
(142,73,16,4,(124,30,31)),(154,69,9,4,(124,30,31)),(154,77,9,5,(124,30,31)),
(158,82,9,4,(124,30,31)),(150,86,8,4,(124,30,31)),(142,69,4,4,(124,30,31)),
(137,77,6,5,(124,30,31)),(137,94,13,4,(245,42,44)),(150,90,12,4,(245,42,44)),
(129,86,21,4,(245,42,44)),(133,82,9,4,(245,42,44)),(137,69,5,8,(245,42,44)),
(146,69,8,4,(245,42,44)),(143,77,11,5,(245,42,44)),(150,82,8,4,(245,42,44)),
(158,73,13,4,(245,42,44)),(163,77,4,5,(245,42,44)),(163,69,4,4,(245,42,44)),
(175,73,4,4,(245,42,44)),(179,82,5,8,(245,42,44)),(184,85,8,5,(245,42,44)),
(167,90,12,8,(245,42,44)),(167,82,8,3,(245,42,44)),(158,86,9,3,(245,42,44)),
(158,89,4,1,(245,42,44)),(150,102,4,13,(15,65,23)),(167,102,3,9,(15,65,23)),
(162,111,5,8,(15,65,23)),(154,111,4,8,(15,65,23)),(158,119,4,92,(15,65,23)),
(138,120,5,5,(15,65,23)),(143,123,7,2,(15,65,23)),(142,125,2,11,(15,65,23)),
(179,119,4,4,(15,65,23)),(177,123,2,12,(15,65,23)),(171,123,6,2,(15,65,23)),
(171,125,1,4,(15,65,23)),(173,135,6,1,(15,65,23)),(162,141,9,3,(15,65,23)),
(167,129,5,1,(15,65,23)),(162,136,5,1,(15,65,23)),(167,130,1,7,(15,65,23)),
(171,135,2,9,(15,65,23)),(149,125,5,2,(15,65,23)),(150,141,8,3,(15,65,23)),
(152,134,6,2,(15,65,23)),(142,136,8,1,(15,65,23)),(152,127,2,7,(15,65,23)),
(148,137,2,7,(15,65,23)),(154,98,13,13,(23,146,51)),(158,111,4,8,(23,146,51)),
(172,125,5,10,(23,146,51)),(168,130,4,5,(23,146,51)),(168,135,3,6,(23,146,51)),
(162,137,6,4,(23,146,51)),(150,136,8,5,(23,146,51)),(144,125,5,11,(23,146,51)),
(149,127,3,9,(23,146,51)),
fig1 = plt.figure()
ax1 = fig1.add_subplot(111,aspect='equal')
plt.xlim(70,250)
plt.ylim(20,240)
for r in rects:
ax1.add_patch(
patches.Rectangle(
(r[0], 250-r[1]), # (x,y)
width = r[2], # width
height = -r[3], # height
facecolor =
(r[4][0]/255,r[4][1]/255,r[4][2]/255),#color
plt.pause(0.01)
plt.show()
效果图
C++ 源程序代码九
#include
#include
#include
// 定义全局变量
int rosesize = 500;
int h = -250;
// 定义结构体
struct DOT
double x;
double y;
double z;
double r; // 红色
double g; // 绿**(蓝色)通过 r计算
// 计算点
bool calc(double a, double b,double c, DOT &d)
double j, n, o, w, z;
if(c > 60) // 花柄
d.x = sin(a * 7) * (13 + 5 / (0.2+ pow(b * 4, 4))) - sin(b) * 50;
d.y = b * rosesize + 50;
d.z = 625 + cos(a * 7) * (13 + 5/ (0.2 + pow(b * 4, 4))) + b * 400;
d.r = a * 1 - b / 2;
d.g = a;
return true;
double A = a * 2 - 1;
double B = b * 2 - 1;
if(A * A + B * B < 1)
if(c > 37) // 叶
j = (int(c) & 1);
n = j ? 6 : 4;
o = 0.5 / (a + 0.01) + cos(b *125) * 3 - a * 300;
w = b * h;
d.x = o * cos(n) + w * sin(n) +j * 610 - 390;
d.y = o * sin(n) - w * cos(n) +550 - j * 350;
d.z = 1180 + cos(B + A) * 99 - j* 300;
d.r = 0.4 - a * 0.1 + pow(1 - B* B, -h * 6) * 0.15 - a * b * 0.4 + cos(a + b) / 5 + pow(cos((o * (a+ 1) + (B > 0 ? w : -w)) / 25), 30) * 0.1 * (1 - B * B);
d.g = o / 1000 + 0.7 - o * w *0.000003;
return true;
if(c > 32) // 花萼
c = c * 1.16 - 0.15;
o = a * 45 - 20;
w = b * b * h;
z = o * sin(c) + w * cos(c) +620;
d.x = o * cos(c) - w * sin(c);
d.y = 28 + cos(B * 0.5) * 99 - b* b * b * 60 - z / 2 - h;
d.z = z;
d.r = (b * b * 0.3 + pow((1 - (A* A)), 7) * 0.15 + 0.3) * b;
d.g = b * 0.7;
return true;
// 花
o = A * (2 - b) * (80 - c * 2);
w = 99 - cos(A) * 120 - cos(b) *(-h - c * 4.9) + cos(pow(1 - b, 7)) * 50 + c * 2;
z = o * sin(c) + w * cos(c) +700;
d.x = o * cos(c) - w * sin(c);
d.y = B * 99 - cos(pow(b, 7)) *50 - c / 3 - z / 1.35 + 450;
d.z = z;
d.r = (1 - b / 1.2) * 0.9 + a *0.1;
d.g = pow((1 - b), 20) / 4 +0.05;
return true;
return false;
// 主函数
void main()
// 定义变量
short *zBuffer;
int x, y, z, zBufferIndex;
DOT dot;
// 初始化
initgraph(640, 480); // 创建绘图窗口
setbkcolor(WHITE); // 设置背景色为白色
cleardevice(); // 清屏
// 初始化z-buffer
zBuffer = new short[rosesize *rosesize];
memset(zBuffer, 0, sizeof(short)* rosesize * rosesize);
for(int j = 0; j < 2000 &&!_kbhit(); j++) // 按任意键退出
for(int i = 0; i < 10000; i++) // 减少是否有按键的判断
if(calc(double(rand()) /RAND_MAX, double(rand()) / RAND_MAX, rand() % 46 / 0.74, dot))
z = int(dot.z + 0.5);
x = int(dot.x * rosesize / z - h+ 0.5);
y = int(dot.y * rosesize / z - h+ 0.5);
if (y >= rosesize) continue;
zBufferIndex = y * rosesize + x;
if(!zBuffer[zBufferIndex] ||zBuffer[zBufferIndex] > z)
zBuffer[zBufferIndex] = z;
// 画点
int r = ~int((dot.r * h)); if (r< 0) r = 0; if (r > 255) r = 255;
int g = ~int((dot.g * h)); if(g < 0) g = 0; if (g > 255) g = 255;
int b = ~int((dot.r * dot.r *-80)); if (b < 0) b = 0; if (b > 255) b = 255;
putpixel(x + 50, y - 20, RGB(r,g, b));
Sleep(1);
// 退出
delete []zBuffer;
_getch();
closegraph();
效果图
今天母亲节,记得要给母亲说一声“妈妈,谢谢!我爱你哦!”
想要具体的MATLAB源程序m文件
请在微信公众号后台
联系模小数领取哦
戳我戳我
温馨提示:微信公众号信息流改版,每个用户可以设置常读订阅号,这些订阅号将以大卡片的形式展示。因此,如果不想错过“校苑数模”的文章,第一时间获得国赛资讯、答案查询、你一定要进行以下操作:进入“校苑数模”公众号 → 点击右上角的 ··· 菜单 → 选择「设为星标」
热门跟贴