@740340735
2016-01-11T12:23:33.000000Z
字数 3043
阅读 809
科学计算
陆一洲 5140309557
double x=1;for (int i=0; i<=16; i++){double h=pow(10.0, -i),a=(tan(x+h)-tan(x))/h,b=1.0/sqr(cos(x));fprintf(FOUT, "%d\t%.25lf\n", i, fabs(a-b));}for (int i=0; i<=16; i++){double h=pow(10.0, -i),a=(tan(x+h)-tan(x-h))/h/2,b=1.0/sqr(cos(x));fprintf(FOUT, "%d\t%.30lf\n", i, fabs(a-b));}
double ans=0, x;scanf("%lf", &x);for (int i=0; ; i++){double inc=Power(x, i)/Factorial((double)i);if (ans+inc==ans) break;ans+=inc;}printf("%.30lf\t%.30lf\t%.30lf\n", ans, exp(x), ans-exp(x));
| Tayler_exp() | exp() | 绝对误差 | 相对误差 | |
|---|---|---|---|---|
| -20 | 8.359241e-009 | 2.061154e-009 | 6.298087e-009 | 7.534281e-001 |
| -15 | 3.059036e-007 | 3.059023e-007 | 1.319961e-012 | 4.314957e-006 |
| -10 | 4.539993e-005 | 4.539993e-005 | 1.241689e-014 | 2.735002e-010 |
| -5 | 6.737947e-003 | 6.737947e-003 | 1.232607e-016 | 1.829350e-014 |
| -1 | 3.678794e-001 | 3.678794e-001 | 6.795237e-017 | 1.847137e-016 |
| 1 | 2.718282e+000 | 2.718282e+000 | 2.994566e-016 | 1.101639e-016 |
| 5 | 1.484132e+002 | 1.484132e+002 | 3.191891e-014 | 2.150679e-016 |
| 10 | 2.202647e+004 | 2.202647e+004 | 5.902834e-012 | 2.679882e-016 |
| 15 | 3.269017e+006 | 3.269017e+006 | 3.092282e-011 | 9.459362e-018 |
| 20 | 4.851652e+008 | 4.851652e+008 | 1.199078e-007 | 2.471484e-016 |
| Tayler_exp() | exp() | 绝对误差 | 相对误差 | |
|---|---|---|---|---|
| -20 | 2.061154e-009 | 2.061154e-009 | 4.564034e-025 | 2.214310e-016 |
| -15 | 3.059023e-007 | 3.059023e-007 | 2.481542e-024 | 8.112203e-018 |
| -10 | 4.539993e-005 | 4.539993e-005 | 9.423242e-021 | 2.075607e-016 |
| -5 | 6.737947e-003 | 6.737947e-003 | 1.639432e-018 | 2.433133e-016 |
| -1 | 3.678794e-001 | 3.678794e-001 | 4.306993e-017 | 1.170762e-016 |
| Tayler_exp() | exp() | 绝对误差 | 相对误差 | |
|---|---|---|---|---|
| -20 | 2.061154e-009 | 2.061154e-009 | 4.281306e-026 | 2.077141e-017 |
| -15 | 3.059023e-007 | 3.059023e-007 | 5.045802e-023 | 1.649481e-016 |
| -10 | 4.539993e-005 | 4.539993e-005 | 1.090555e-020 | 2.402107e-016 |
| -5 | 6.737947e-003 | 6.737947e-003 | 9.529121e-020 | 1.414247e-017 |
| -1 | 3.678794e-001 | 3.678794e-001 | 1.244122e-017 | 3.381874e-017 |
- (Matlab test) For n=500, 1000, 2000, 4000, 8000, generate an n*n random matrix, B, and an n*1 vector, b. Find the symmetric matrix A=B’*B.
1) Using function “eig” to test the time cost for eigen decomposition;
2) Using x=A\b and x=A^(-1)*b to test the time cost in finding the solution of Ax=b;
3) Plot all the time costs as a function of n and the power law for the time costs.
| 用时() | 0.263475 | 1.279685 | 6.288209 | 38.239515 | 269.477866 |
| 0.007135 | 0.037733 | 0.213802 | 1.326795 | 9.614620 | |
| 0.030764 | 0.134277 | 0.848402 | 5.948203 | 55.072248 |
General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 2.975e-09 (1.234e-09, 4.717e-09)
b = 2.807 (2.742, 2.872)
Goodness of fit:
SSE: 0.9548
R-square: 1
Adjusted R-square: 1
RMSE: 0.5641

General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 7.369e-11 (3.274e-11, 1.146e-10)
b = 2.848 (2.786, 2.91)
Goodness of fit:
SSE: 0.001032
R-square: 1
Adjusted R-square: 1
RMSE: 0.01855

General model Power1:
f(x) = a*x^b
Coefficients (with 95% confidence bounds):
a = 1.785e-11 (3.07e-12, 3.263e-11)
b = 3.2 (3.108, 3.292)
Goodness of fit:
SSE: 0.04505
R-square: 1
Adjusted R-square: 1
RMSE: 0.1225