用mathematica编写

第一题

a = Input[];
b = Input[];
a + b

测试

输入
a = 12370128301283012809381209381902380912830128038120389102830912803981203810928309128309128031808309128398

b = 1237012830128301280938120938190238091283012803812038910283091280398120381092830912830912803180830912839812370128301283012809381209381902380912830128038120389102830912803981203810928309128309128031808309128398

结果
1237012830128301280938120938190238091283012803812038910283091280398120381092830912830912803180830912839824740256602566025618762418763804761825660256076240778205661825607962407621856618256618256063616618256796

第二题. 输入正整数N

count[x_] := Total[Select[Flatten[x], # > 5 &]];
n = Input[];
random = RandomInteger[{-20, 10}, {n, 2 n}];
count[random];

测试结果

第三题

Plot[Evaluate[Normal[Series[Sin[x], {x, 0, 40}]]], {x, 0, 5 Pi}]
N@((f[10] - Sin[10])/Sin[10])
N@f[10]
N@Sin[10]

Plot[Evaluate[Normal[Series[Cos[x], {x, 0, 40}]]], {x, 0, 5 Pi}]
f[x_] := Evaluate[Normal[Series[Cos[x], {x, 0, 40}]]]
f[10.78]
(f[10.78] -Cos[10.78])/Cos[10.78]

结果

-0.213908

误差为
-7.34755*10^-8

过程

首先找到sin(x)误差较小的阶数

可以看出当阶数越多, 越逼近原函数,
这里取40

基本逼近
测试一个数
f[10] = -0.544021
Sin[10] = -0.544021
这里只选取了小数点前6位

对cos(x)同理

选x的阶数为40
此时近似函数如下

形式为

带入解得
f[10.78] = -0.213908

第四题

f1[x_] := Sin[x]/x;
test = Range[1, 2, 0.00001];
int = NIntegrate[Sin[x]/x, {x, 1, 2}]
SelectFirst[test, (f1[#] - int) < 0.0000000000000001 &]

结果

1.51427

第六题

f = x1^2 + x2^2 + 3 x3^2 + 4 x4^2 + 2 x5^2 - 8 x1 - 2 x2 - 3 x3 - 
   x4 - 2 x5;
NMaximize[{f, 
  x1 + x2 + x3 + x4 + x5 <= 400 && x1 + 2 x2 + 2 x3 + x4 + x5 <= 800 &&
    2 x1 + x2 + 6 x3 <= 200 && x3 + x4 + 5 x5 <= 200 && 
   0 <= x1 <= 99 && 0 <= x2 <= 99 && 0 <= x3 <= 99 && 0 <= x4 <= 99 &&
    0 <= x5 <= 99}, {x1, x2, x3, x4, x5}, 
 Method -> {"SimulatedAnnealing", "PerturbationScale" -> 3, 
   "BoltzmannExponent" -> Function[{i, df, f0}, -df/(Exp[i/10])]}]

结果

51629.9

其中
x1, x2, x3, x4, x5
分别为
50.5,
99.,
7.69923*10^-9,
99.,
20.2