matlab绘图题

来源:互联网 发布:linux就该这样学.pdf 编辑:程序博客网 时间:2024/05/19 17:59

第一题

题目

这里写图片描述

代码

clear clcP = [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 allhold ontime = [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 ally = @(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 onplot(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 onaxis([])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 onx1 = [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 onmesh(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    endendm=max(temp); for k = 1:42    if temp(k) == m        d = temp1(k);    endendx=Vx(d).*t; y=Vy(d).*t - 0.5.*g.*(t.^2);plot(x,y,'b-','LineWidth', 5); sprintf('水平位移最大为:%.3f 米',m)

结果

这里写图片描述

0 0
原创粉丝点击