第一題
題目
代碼
clear clc
P = [12, 64, 25, 12, 18];
subplot(2, 2, [2,4]);
bar(P), title('圖(2)');
subplot(2, 2, 1);
explode = [0 1 0 1 1];
pie(P,explode);
colormap jet;
title('圖(1)');
legend('家教兼職', '上網', '逛街', '旅遊觀光', '睡覺');
subplot(2, 2, 3);
pie3(P,[0 1 0 1 1],{ '家教兼職', '上網', '逛街', '旅遊觀光', '睡覺'});
運行結果
第二題
題目
代碼
clear clc close all
hold on
time = [0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 5.0 6.0 6.1 7.0];
temp = [300 281 261 244 228 214 202 191 181 164 151 149 141];
scatter(time, temp,'k'), xlabel('time'), ylabel('temp');
f = polyfit(time, temp, 4);
y = polyval(f, time);
plot(time, y, 'r'), legend('實際值', '擬合值');
y9 = polyval(f, 9);
plot(9, y9, 'rs');
運行結果
第三題
題目
代碼
clear clc close all
y = @(t) sin(t).*sin(9*t);
x1 = 0:1/4:3;
x2 = 0:1/30:3;
x4 = 0:3/1000:3;
subplot(2, 2, 1)
scatter(x1, y(x1), 'r.');
axis([0 4 -1 1]);
title('子圖(1)');
subplot(2, 2, 2)
scatter(x2, y(x2), 'r.');
axis([0 4 -1 1]);
title('子圖(2)');
subplot(2, 2, 3)
plot(x1, y(x1), 'r.');
hold on
plot(x1, y(x1), 'b-');
axis([0 4 -1 1]);
title('子圖(3)');
subplot(2, 2, 4)
plot(x4, y(x4));
axis([0 4 -1 1]);
title('子圖(4)');
結果
第四題
題目
代碼
close all, clear, clc
subplot(2, 2, 1)
a = 2;
theta = [0: pi/90: 2*pi];
r = a*(1-cos(theta));
h = polar(theta, r, 'r'),title('心形圖 r = 2(1-cos(\theta))');
set(h, 'LineWidth', 5);
subplot(2, 2, 3)
t = 0: 10*pi/100: 10*pi;
x = 2 * cos(t);
y = 3 * sin(t);
z = t;
plot3(x, y, z, 'r')
grid on
axis([])
xlabel('2cos(t)'), ylabel('3sin(t)'), title('三維曲線圖t在[0, 10*pi]');
subplot(2, 2, [2, 4])
rectangle('Position',[0,4,0,2]);
x = [0 0 4 4];
y = [0 2 2 0];
fill(x,y,'r');
hold on
x1 = [0 4 2];
y1 = [2 2 4];
fill(x1,y1,'b');
title('填充圖');
結果
第五題
題目
代碼
close all, clear, clc
[x,y]=meshgrid(-10:0.2:10);
a=1;b=2;c=3;
z1=sqrt(c.^2*(x.^2/(a.^2)+y.^2/(b.^2)));
z2=-sqrt(c.^2*(x.^2/(a.^2)+y.^2/(b.^2)));
mesh(x,y,z1)
hold on
mesh(x,y,z2)
結果
第六題
題目
(y的最後一個符號應該爲-)
代碼
%該題y的最後一個符號應該是-
clear all;
close all;
clc;
g=9.81; a=5: 10: 85; t=0:0.1:4.2;
Vx=20.*cos(pi*a/180); Vy=20.*sin(pi*a/180);
hold on;
axis([0 45 0 22])
for i=1:1:9
x=Vx(i).*t;
y=Vy(i).*t - 0.5.*g.*(t.^2);
if rem(i,3)==0 plot(x,y,'b');
elseif rem(i,3)==1 plot(x,y,'g');
elseif rem(i,3)==2 plot(x,y,'r');
end
for j=2:1:43
if y(j)<=0
temp(j)=x(j);
temp1(j) = i;
sprintf('第%d次拋出 水平位移:%.3d', i, x(j))
break;
end
end
end
m=max(temp);
for k = 1:42
if temp(k) == m
d = temp1(k);
end
end
x=Vx(d).*t;
y=Vy(d).*t - 0.5.*g.*(t.^2);
plot(x,y,'b-','LineWidth', 5);
sprintf('水平位移最大爲:%.3f 米',m)