一、 程序编程题
chickens=1;
while chickens<=35
rabbits = 35 - chickens;
feet=chickens * 2 + rabbits * 4;
if feet==94
fprintf('鸡 有 %d 只\n',chickens)
fprintf('兔子 有 %d 只\n',rabbits)
break
end
chickens = chickens+1;
end
2.鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一;百钱买百鸡,则翁、母、雏各几何?(请用for循环编程实现)
for cock = 0:100/5
for hen = 0:100/3
chick = 100-cock-hen;
if cock*5 + hen*3 + chick/3 == 100
fprintf('公鸡买%d只;',cock);
fprintf('母鸡买%d只;',hen);
fprintf('小鸡买%d只\n',chick);
end
end
end
t = 0:0.1:2*pi;
x = 16*sin(t).^3;
y = 13*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t);
plot(x,y);
x = 0:0.05:4*pi;
y1 = sin(x);
y2 = cos(x);
plot(x,y1,'ro',x,y2,'k-');
title('正余弦函数');
text(pi,0,' \leftarrow y=sin(x)');
text(2.5*pi,0,' \leftarrow y=cos(x)');
xlabel('x轴');
ylabel('y轴');
3.在同一平面中的两个窗口分别画出心形线和马鞍面.要求:
(1)在图形上加格栅、图例和标注
(2)定制坐标,区间自定
(3)以不同角度观察马鞍面
theta=-pi:0.01:pi;
x=cos(theta);
y=sin(theta)+((cos(theta)).^2).^(1/3);
plot(x,y,'r');
grid;
legend('心形线');
4.绘制三维曲面图z=sin(x+sin(y))-x/10
t = 0:0.25:4*pi;
[x,y] = meshgrid(t);
z = sin(x+sin(y))-x/10;
surf(x,y,z);
5.利用peaks产生数据,绘制多峰曲面图
z=peaks(50);
mesh(z);
figure;
surf(z);
6.绘制peaks函数的表面图,用colormap函数改变预置的色
图,观察色彩的分布情况。
(请将每题的程序代码,运行结果或生成图形,保存在word文件里上交)。
[x,y,z]=peaks(10);
axes1=subplot(2,2,1);
surf(x,y,z);
colormap(axes1,spring);
title('spring');
axes2=subplot(2,2,2);
surf(x,y,z);
colormap(axes2,autumn);
title('summer');
axes3=subplot(2,2,3);
surf(x,y,z);
colormap(axes3,flag);
title('flag');
axes4=subplot(2,2,4);
surf(x,y,z);
colormap(axes4,pink);
title('pink');