📄 11.txt
字号:
clc;
clear;
f=figure(6);
x=0:0.1:2*pi;
y=sin(x);
l=plot(x,y);
a=gca;
gf=get(f);
gl=get(l);
ga=get(a);
gt=get(a,'title');
haha=get(gt)
set(gt,'string','正弦函数');
gc=get(l,'color')
set(l,'color',[1,0,0])
clc
figure(1)
x=0:0.1*pi:2*pi;
y=sin(x);
plot(x,y,'-*g');
axis ('equal');
grid on;
title('正弦函数');
xlabel('X轴','FontName','黑体'); %第一题
figure(2)
x=0:0.1*pi:2*pi;
subplot(2,2,1);
plot(x,x.^2,'-*r',x,-x.^2,'-ob',x,x.^2.*sin(x),'-^m');
title('y=x^2');
subplot(2,2,2);
plot(x,-x.^2,'-ob');
title('y=-x^2');
subplot(2,2,3);
plot(x,x.^2.*sin(x),'-^m');
title('y=x^2*sin(x)');
subplot(2,2,4);
t=0:0.1*pi:2*pi;
x=sin(t);
y=cos(t);
plot3(x,y,t,'g');
title('3D image'); %第二题
figure(3)
subplot(2,3,1);
[x,y]=meshgrid(-5:0.2:5,-5:0.2:5);
plot3(x,y,x.*exp(-x.^2-y.^2));
title('plot3');
subplot(2,3,2);
[X,Y]=meshgrid([-5:0.2:5]);
Z=X.*exp(-X.^2-Y.^2);
mesh(Z);
title('mesh');
subplot(2,3,3);
[X,Y]=meshgrid([-5:0.2:5]);
Z=X.*exp(-X.^2-Y.^2);
meshc(Z);
title('meshc');
subplot(2,3,4);
[X,Y]=meshgrid([-5:0.2:5]);
Z=X.*exp(-X.^2-Y.^2);
meshz(Z);
title('meshz');
subplot(2,3,5);
[X,Y]=meshgrid([-5:0.2:5]);
Z=X.*exp(-X.^2-Y.^2);
surf(Z);
light('position',[1,0.5,2]);
colormap(spring);
title('surf'); %第三题
figure(4)
[X,Y]=meshgrid(-8:0.1:8,-10:0.1:10);
Z=sin(X.*Y)+cos(X.*Y);
meshz(Z);
function f=lsq()
x=[1978:2005];
y=[9.5416 9.6996 9.8573 10.014 10.171 10.327 10.482 10.636 10.790 10.942 11.093 11.243 11.392 11.540 11.686 11.830 11.973 12.115 12.255 12.393 12.529 12.663 12.796 12.927 13.055 13.182 13.315 13.330];
canshu=[20,3,2,1900];
canshu=lsqcurvefit('func1',[20,3,2,1970],x,y)
xx=[1978:2020];
yy=canshu(1)./(1+canshu(2).*exp(-canshu(3).*(xx-canshu(4))));
plot(xx,yy,'r')
yw=canshu(1)./(1+canshu(2).*exp(-canshu(3).*(x-canshu(4))));
norm(yw-y) %误差
xy=[2006:2020];
yy=canshu(1)./(1+canshu(2).*exp(-canshu(3).*(xy-canshu(4)))) %2020年前的人口总数
function f=pingfang()
x=[1978:2005];
y=[9.5416 9.6996 9.8573 10.014 10.171 10.327 10.482 10.636 10.790 10.942 11.093 11.243 11.392 11.540 11.686 11.830 11.973 12.115 12.255 12.393 12.529 12.663 12.796 12.927 13.055 13.182 13.315 13.330];
n=27;
xx1=0;
for i=1:27
xx1=xx1+y(i)^0;
end
xx2=0;
for i=1:27
xx2=xx2+y(i)^1;
end
xx3=0;
for i=1:27
xx3=xx3+y(i)^2
end
yy1=0;
for i=1:27
yy1=yy1+(y(i+1)-y(i));
end
yy2=0;
for i=1:27
yy2=yy2+(y(i+1)-y(i))*y(i);
end
A=[xx1 xx2;xx2 xx3];
b=[yy1;yy2];
c=A\b;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -