octave的代码主要
%samp3_27.m r=linspace(0,2*pi,60); [u,v]=meshgrid(r); x=(8+3*cos(v)).*cos(u); y=(8+3*cos(v)).*sin(u); z=3*sin(v); plot3(x,y,z); title('三维绘图'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴');
%samp3_30.m x=-10:0.5:10; [xx,yy]=meshgrid(x); zz=sin(sqrt(xx.^2 + yy.^2))./sqrt(xx.^2 + yy.^2) subplot(2,2,1); surf(xx,yy,zz); title('三维曲面图'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴'); subplot(2,2,2); sphere(20); title('球面图'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴'); subplot(2,2,3); [x, y, z] = cylinder (10:-0.1:9.9, 150); surf (x, y, z); title ("a cone"); %cylinder(10); %octave中上一行代码无法运行 title('柱面图'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴'); subplot(2,2,4); peaks; title('多峰图'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴');
%samp3_31 [x,y,z]=meshgrid(-2:0.2:2, -2:0.25:2, -2:0.2:2); V=x.*exp(-x.^2-y.^2-z.^2); %slice(x,y,z,V,[-0.5,0.8,1.5], 0.5, []); slice(x,y,z,V,[-0.5,0.8,1.5], 0.5, [-1,1]); xlabel('x轴'); ylabel('y轴'); zlabel('z轴');
%samp3_32 clc; x = 0:2*pi; y = sin(x); xx = 0:0.5:2*pi; grid on; subplot(2, 2, 1); plot(x, y); title('原函数图'); xlabel('x轴'); ylabel('y轴'); grid on; y1 = interp1(x, y, xx, 'linear'); subplot(2, 2, 2); plot(x, y, 'o', xx, y1, 'r'); title('线性插值'); xlabel('x轴'); ylabel('y轴'); grid on; y2 = interp1(x, y, xx, 'nearest'); subplot(2, 2, 3); plot(x, y, '+', xx, y2, 'g'); title('最邻近插值'); xlabel('x轴'); ylabel('y轴'); grid on; y3 = interp1(x, y, xx, 'spline'); subplot(2, 2, 4); plot(x, y, '>', xx, y3, 'b'); title('三次样条插值'); xlabel('x轴'); ylabel('y轴'); grid on;
%samp3_33 clf; clc; x = 0:2:24; y = [12, 9, 9, 10, 18, 24, 28, 25, 20, 16, 12, 11, 11]; x1 = 9; y1 = interp1(x, y, x1, 'spline'); plot(x, y, 'b - >', x, y, x1, y1, 'r-h'); %plot(x, y, 'g - >', x1, y1, 'r-h'); title('插值点绘图'); text(x1 - 2, y1, '插值点');
%samp3_34 clear; year = 2000:2:2020; product = [90 105 123 131 150 179 203 226 249 256 267]; subplot(2, 1, 1); plot(year, product, 'r - h') title('插值前:2000年 - 2020年的产量'); xlabel('年份'); ylabel('产量'); subplot(2, 1, 2); x = 2000:1:2020; y = interp1(year, product, x); p2015 = interp1(year, product, 2015); plot(year, product, 'b-+', x, y, 'r*h'); title('2000年 - 2020年的产量'); xlabel('年份'); ylabel('产量'); text(2015 - 3, p2015, '2015的产量');
%samp3_35 clear; x = [0 2 4 5 8 12 12 12.8 17.2 19.9 20]; y = exp(x).* sin(x); subplot(3, 1, 1); plot(x, y, 'o'); xlabel('x轴'); ylabel('y轴'); grid on; xx = 0:0.25:20; yy = interp1(x, y, xx, 'spline'); subplot(3, 1, 2); plot(x, y, 'o', xx, yy); xlabel('x轴'); ylabel('y轴'); grid on; yy1 = interp1(x, y, xx, 'linear'); subplot(3, 1, 3); plot(x, y, 'o', xx, yy1); xlabel('x轴'); ylabel('y轴'); grid on;
%samp3_35_2 clear; clf; x = [0 2 4 5 8 12 12 12.8 17.2 19.9 20]; y = exp(x).* sin(x); xx = 0:0.25:20; xx1 = 18.75; yy = interp1(x, y, xx, 'nearest'); plot(x, y, 'o', xx, yy); hold on yy1 = interp1(x, y, xx, 'linear'); plot(x, y, 'o', xx, yy1); xlabel('x轴'); ylabel('y轴'); hold on grid on;
%samp3_36 clc; clf; years = 1980:10:2020; times = 10: 10: 30; salary = [1500 1990 2000; 3010 3500 4000; 4100 4200 4500; 5600 7000 8000; 95000 10000 12000]; S = interp2(times, years, salary, 12, 2000); S
%samp3_37 clf; clc; [x, y] = meshgrid(-8:0.8:8); z = sin(sqrt(x.^2 + y.^2))./sqrt(x.^2 + y.^2); subplot(2, 2, 1); surf(x, y, z); title('原图'); [x1, y1] = meshgrid(-8:0.5:8); z1 = interp2(x, y, z, x1, y1); subplot(2, 2, 2); surf(x1, y1, z1); title('linear'); z2 = interp2(x, y, z, x1, y1, 'cubic'); subplot(2, 2, 3); surf(x1, y1, z2); title('cubic'); z3 = interp2(x, y, z, x1, y1, 'spline'); subplot(2, 2, 4); surf(x1, y1, z3); title('spline');
%samp3_38 clc; clf; [x, y, z] = meshgrid(-1:0.1:1); [x1, y1, z1] = meshgrid(-1:0.1:1); V = x.^2 + y.^2 + z.^2; V1 = interp3(x, y, z, V, x1, y1, z1, 'spline'); x0 = [-0.5, 0.5]; y0 = [0.4, -0.4]; z0 = [-0, -0.75, 0.75]; slice(x1, y1, z1, V1, x0, y0, z0); title('三维拟合'); xlabel('x轴'); ylabel('y轴'); zlabel('z轴');
人就像是被蒙着眼推磨的驴子,生活就像一条鞭子;当鞭子抽到你背上时,你就只能一直往前走,虽然连你也不知道要走到什么时候为止,便一直这么坚持着。