目录

数学建模与数学实验第5版-作图-习题2.6

《数学建模与数学实验》第5版 作图 习题2.6

文章目录

    • [(3)编程求

      ∑ n

      1 20 n ! \displaystyle\sum_{n=1}^{20} n!

      n

      =

      1

      2

      0

      n

      !](#3displaystylesum_n120_n_39)

  • [3.用ezplot绘制函数

    e x y e^{xy}

    e

    x

    y -sin(x+y)=0在[-3,3]上图形.](#3ezplotexysinxy033_100)

  • [4. 用ezplot绘制摆线

    f ( x )

    { x

    t − sin ⁡ ( t ) y

    1 − cos ⁡ ( t ) f(x)=\left{\begin{aligned}x & = &t- \sin(t) \y & = & 1-\cos(t) \end{aligned}\right.

    f

    (

    x

    )

    =

    {

    x

    y

    =

    =

    t

    sin

    (

    t

    )

    1

    cos

    (

    t

    )

    ​](#4_ezplot__fxleftbeginalignedx___t_sint_y____1cost_endalignedright_106)

  • [5. 用surf、mesh绘制曲面z=

    2 x 2 + y 2 2x^2+y^2

    2

    x

    2

y

2 .](#5_surfmeshz2x2y2_112)

  • [6. 用polarplot绘制阿基米德线r =

    a θ a\theta

    a

    θ 和三叶玫瑰线r=

    a c o s 3 θ acos3\theta

    a

    c

    o

    s

    3

    θ .](#6_polarplotr_athetaracos3theta_125)

参考教材:《数学建模与教学实验》第5版

提示:以下是本篇文章正文内容,来自参考教材课后习题。

1.编写m文件

(1)用起泡法对10个数由小到大排序. 即将相邻两个数比较,将小的调到前头.

建立qipao函数:

function y = qipao(x)
n = length(x);%求数组个数
%气泡排序
for a = 1:n
    for b = 1:n-a
    if(x(b)>x(b+1))
        c = x(b);
        x(b) = x(b+1);
        x(b+1) = c;
    end
    end
end
y = x
        

测试:

https://i-blog.csdnimg.cn/blog_migrate/96e332d4e0178be13273b015e8f192a4.png

(2)有一个4x5矩阵,编程求出其最大值及其所处的位置.

建立 max1函数:


function max1(x)
[a,b] = max(x);%求出矩阵每列的最大值a和最大值的行数b
[c,d] = max(a);%求出矩阵最大值c与最大值列下标d
b(d);%最大值行下标
disp(['最大值:',num2str(c)]);
disp(['位于:',num2str(b(d)),'行',num2str(d),'列']);
end

测试:

https://i-blog.csdnimg.cn/blog_migrate/1c1c45a84ffa56e4bcd4b995b3b97eae.png

(3)编程求 ∑ n = 1 20 n ! \displaystyle\sum_{n=1}^{20} n! n = 1 ∑ 2 0 ​ n !

建立jiec函数:

function f = jiec(n)
sum = 0;

for i = 1:n
    p = 1;
    j = 1;
    for j = 1:i
        p = p * j;
        j = j - 1;
    end
    sum = sum + p;
    i = i + 1;
end
f = sum;
end

测试:

https://i-blog.csdnimg.cn/blog_migrate/5b915448343acca0d61324fc133cd76a.png

(4)一球从100米高度自由落下,每次落地后反跳回原高度的一半,再落下. 求它在第10次落地时,共经过多少米?第10次反弹有多高?

建立fantanh函数:

function [s,h] = fantanh(n)
z = 100;
s = 100;
for i = 1:n
    z = z/2;
    s = s + 2*z;
end
h = z/2

测试:

https://i-blog.csdnimg.cn/blog_migrate/5c82c8aad56cd45818ae3c39218b50a5.png

(5)有一函数f(x,y)=x2+sin(xy)+2y,写一程序,输入自变量的值,输出函数值.

建立fun函数:

function y = fun(x,y)
y = x.^2 + sin(x*y) + 2*y;

测试:

https://i-blog.csdnimg.cn/blog_migrate/2a5e2a45dd59568ff0c45062f74021a9.png

2. 用plot、fplot绘制函数y=cos(tan(πx))图形.

%% plot fplot
x = linspace(0,2*pi);
y = cos(tan(pi*x));
subplot(1,2,1);plot(x,y);title('plot')
subplot(1,2,2);fplot(@(x) cos(tan(pi.*x)),[0,2*pi]);title('fplot')

https://i-blog.csdnimg.cn/blog_migrate/041317b192619167937a9d5792b58974.png

3.用ezplot绘制函数 e x y e^{xy} e x y -sin(x+y)=0在[-3,3]上图形.

ezplot('exp(x*y)-sin(x + y)',[-3,3,-3,3])

https://i-blog.csdnimg.cn/blog_migrate/b975d64f59865261845c99ead83f5d0a.png

4. 用ezplot绘制摆线 f ( x ) = { x = t − sin ⁡ ( t ) y = 1 − cos ⁡ ( t ) f(x)=\left{\begin{aligned}x & = &t- \sin(t) \y & = & 1-\cos(t) \end{aligned}\right. f ( x ) = { x y ​ = = ​ t − sin ( t ) 1 − cos ( t ) ​

ezplot('t-sin(t)','1-cos(t)',[0,2*pi])

https://i-blog.csdnimg.cn/blog_migrate/5f96009e6df188fc6323ccad5ddd567f.png

5. 用surf、mesh绘制曲面z= 2 x 2 + y 2 2x^2+y^2 2 x 2 + y 2 .

%% surf.mesh
x = -3:0.1:3;
y = -3:0.1:3;
[X,Y] = meshgrid(x,y);
Z = 2 * X^2 + Y^2;
subplot(1,2,1);surf(X,Y,Z);title('surf')
subplot(1,2,2);mesh(X,Y,Z);title('mesh')

https://i-blog.csdnimg.cn/blog_migrate/7fc4dab402e68c0224cb00349289ef66.png

6. 用polarplot绘制阿基米德线r = a θ a\theta a θ 和三叶玫瑰线r= a c o s 3 θ acos3\theta a c o s 3 θ .

%% polar 
%阿基米德线
a = 50;
theta = 0:0.1:2*pi;
rho1 = a * theta;
polarplot(theta,rho1)

%三叶玫瑰线
rho2 = a * cos(3 * theta);
x = -3:0.1:3;
y = -3:0.1:3;
[X,Y] = meshgrid(x,y);
Z = 2 * X^2 + Y^2;
subplot(1,2,1);polarplot(theta,rho1);title('阿基米德线')
subplot(1,2,2);polarplot(theta,rho2);title('三叶玫瑰线')

https://i-blog.csdnimg.cn/blog_migrate/5d2d0e60870c4dd105438a0272cf0040.png

7. 在同一平面的两个窗口中分别画出心形线和马鞍面

要求:在图形上加格栅、图例和标注;定制坐标;以不同的角度观察马鞍面。

%心形
a=0.01
t=0:0.01:2*pi;
x1=a.*(2.*cos(t)-cos(2*t));
y1=a.*(2.*sin(t)-sin(2*t));
%马鞍面
x = linspace(-10,10);
y = linspace(-10,10);
[X,Y] = meshgrid(x,y);%生成网格
Z = X.^2 - Y.^2;
subplot(1,2,1);plot(x1,y1);title('心型图');
subplot(1,2,2);mesh(X,Y,Z);title('马鞍面');

https://i-blog.csdnimg.cn/blog_migrate/5477aa23dbd5bb8c89c2fe9094221a74.png