Questions in category: MatLab (MatLab)

## 1. [MATLAB]编程计算$\sum_{n=1}^{20}n!$.

Posted by haifeng on 2019-06-29 12:59:07 last update 2020-03-11 17:07:35 | Answers (0) | 收藏

[Exer 1.(3)] 《数学建模与数学实验》

function Y=myfun3(n)
s=0;
k=1;
for i=1:n
k=k*i;
s=s+k;
end
disp(s)

>>  1!+2!+3!+4!+5!+6!+7!+8!+9!+10!+11!+12!+13!+14!+15!+16!+17!+18!+19!+20!

out> 2561327494111820313

## 2. [MATLAB]有一个4*5矩阵, 编程求出其元素最大值及所处的位置.

Posted by haifeng on 2019-06-29 09:40:26 last update 2019-06-29 11:34:22 | Answers (2) | 收藏

[Exer 1.(2), P.30] 《数学建模与数学实验》

function f=zuidazhi(x)
a=1;b=1;c=x(1,1);
for i=1:4
for j=1:5
if x(i,j)>c
a=i;b=j;c=x(i,j);
end
end
end
f=[c,a,b]

% for test
% x=rand(4,5)
% zuidazhi(x)

## 3. [MATLAB]用起泡法(冒泡法)对10个数由小到大进行排序

Posted by haifeng on 2019-06-29 09:06:25 last update 2019-06-29 16:10:46 | Answers (1) | 收藏

[Exer P.30, 1]《数学建模与数学实验》

Remark: 当然冒泡法排序不是好的排序算法, 其算法复杂度为 $O(N^2)$.

function f=qipaofa(x)
for j=9:-1:1
for i=1:j
if(x(i)>x(i+1))
t=x(i);x(i)=x(i+1);x(i+1)=t;
end
end
end
f=x;

% for test
% x=round(10*rand(1,10));

#include<stdio.h>
main()
{int a[10],i,j,t;
printf("请输入10个数:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);

for(j=0;j<9;j++)
for(i=0;i<9-j;i++)
if(a[i]>a[i+1])
{t=a[i];a[i]=a[i+1];a[i+1]=t;}

for(i=0;i<10;i++)
printf("%3d",a[i]);

printf("\n");

}

## 4. MatLab 中生成随机数或服从某种分布的随机数矩阵

Posted by haifeng on 2019-03-01 11:11:46 last update 2019-03-01 11:11:46 | Answers (0) | 收藏

rand(m,n) 生成 $m\times n$ 阶随机数矩阵, 矩阵的元素是 $[0,1]$ 之间的等概率分布的随机数.

## 5. 解微分方程组

Posted by haifeng on 2018-05-07 10:40:15 last update 2018-05-07 10:43:11 | Answers (0) | 收藏

\left\{ \begin{aligned} y'_1&=y_2 y_3,\\ y'_2&=-y_1 y_3,\\ y'_3&=-0.51y_1 y_2,\\ y_1(0)&=0,\quad y_2(0)=1,\quad y_3(0)=1. \end{aligned} \right.

## 6. 求解微分方程 $x''(t)-1000(1-x^2)x'(t)+x=0$.

Posted by haifeng on 2018-05-04 08:29:06 last update 2018-05-07 10:25:31 | Answers (1) | 收藏

$\begin{cases} \dfrac{d^2 x}{dt^2}-1000(1-x^2)\dfrac{dx}{dt}+x(t)=0,\\ x(0)=0,\quad x'(0)=1. \end{cases}$

[Hint]

References:

《数学建模与数学实验》（第四版）P.131

hello

## 7. 求下列微分方程组的通解

Posted by haifeng on 2018-05-02 11:01:04 last update 2018-05-02 11:01:44 | Answers (1) | 收藏

$\begin{cases} \dfrac{dx}{dt}=2x-3y+3z,\\ \dfrac{dy}{dt}=4x-5y+3z,\\ \dfrac{dz}{dt}=4x-4y+2z.\\ \end{cases}$

References:

《数学建模与数学实验》（第四版）P.130

## 8. 求下列微分方程 $y''+4y'+29y=0$ 的解.

Posted by haifeng on 2018-05-02 09:53:15 last update 2018-05-02 10:35:37 | Answers (2) | 收藏

$\begin{cases} \displaystyle\frac{d^2 y}{dx^2}+4\frac{dy}{dx}+29y=0,\\ y(0)=0,\quad y'(0)=15. \end{cases}$

References:

《数学建模与数学实验》（第四版）P.130

## 9. 求 $\dfrac{du}{dt}=1+u^2$ 的通解.

Posted by haifeng on 2018-05-01 18:52:58 last update 2018-05-02 09:53:28 | Answers (2) | 收藏

[hint]

Bernoulli 方程(伯努利方程)

References:

《数学建模与数学实验》（第四版）P.130

## 10. MatLab 入门

Posted by haifeng on 2011-06-28 09:58:42 last update 2019-03-22 13:43:00 | Answers (0) | 收藏