《数值分析》
计算实习题目三
学院
姓名
学号
2015.12
一、 算法设计方案
1. 将
ix
0.08 (
i i
和
,10)
0,1,
jy
0.5 0.05 (
j
j
中,用牛顿法解出 it 和 ju ;
代入非线性方程组
,20)
0,1,
其中 Newton 法求方程组的解 *x (对应未知数为( ,
t u v w ),可采用如下的
)
,
,
算法:
1) 在 *x 附近选取初值 (0)x ,给定精度水平 0 ;
2) 计算
(
F x 和
)
)k
(
F x ,其中有
)
)k
'(
(
(
k
)
(
k
)
(
k
)
(
k
)
(
F x
(
F x
(
F x
(
F x
2
)
1
)
)
)
3
4
(
k
)
k
)
)
(
)
(
)
(
)
)
k
k
k
k
0.5cos(
t
(
t
(
k
0.5
t
(
)
k
t
)
u
(
k
0.5sin(
u
)
)
k
u
0.5
u
v
(
)
v
(
cos(
v
(
)
k
v
w
(
w
)
w
(
k
sin(
w
k
k
k
(
)
(
)
)
(
k
)
)
)
x
y
x
y
2.67
1.07
3.74
0.79
i
j
i
j
'(
F x
(
k
)
)
t
(
k
)
)
0.5sin(
1
0.5
1
1
0.5cos(
1
0.5
u
(
k
)
)
1
1
sin(
1
(
k
v
)
)
1
1
1
cos(
w
(
k
)
)
3) 通过 Doolittle 法求解如下的线性方程组
'(
F x
(
k
)
)
x
(
k
)
(
F x
(
k
)
)
4) 若 (
x
k
)
/
(
k
)
x
,则取 *
x
x
(
)k
,并停止计算,否则进入下一步;
5) 计算 (
x
k
1)
x
(
k
)
,并回到第(2)步。
x
k
(
)
如此反复迭代,即可得到满足精度的非线性方程组的解,即得到各个( ,
t u
i
j
)
j
i
20
0
)
的值。(其中 0 10,
2.以采取分片二次插值,选择(m,n)满足
h
2
2
h
2
2
u
u
u
t
t
t
m
m
n
n
i
j
,2
m
3
,2
n
3
i
t
如果 1
h
2
,
或 n=4。选择 (
t u
k
)(
r
h
2
k m
t 或 4
t
t ,则 m=1 或 4;如果
i
ju
u
2
1
或
ju
u
2
4
,则 n=1
1,
m m
,
1;
r
n
1,
,
n n
1)
为插值节点,相应的 Lagrange
形式的插值多项式为
p
22
( , )
t u
n
1
m
1
1
1
k m r n
其中
l
k
( )
t
m
1
t
t
w
t
t
k
w
1
w m
w k
( ) ( )
t l u f
r
l
k
(
,
t u
k
r
)
(k=m-1, m, m+1)
( )
l u
r
n
1
y
y
r
1
w n
w r
y
w
y
w
(r=n-1, n, n+1)
并将 it 和 ju 代入 22( , )
t u ,便得到了数表 ,
x y
i
p
,
j
(
f x y 。
)
,
i
j
3.进行曲面拟和系数矩阵 [
]rscC
,
其中
C B B B UG G G
(
)
(
T
T
T
1
B [
r
(
x
i
)]
1
1
1
x
0
x
1
x
10
k
x
0
k
x
1
k
x
10
U
[
1
1
1
,
G
[
s
(
y
j
)]
(
,
f x y
i
j
)]
1
)
y
0
y
1
y
10
k
y
0
k
y
1
k
y
10
k 从 0 逐渐增大,直到
710
,便得到了要求精度的系数 rsc 。
4. 计算逼近效果较为简单,首先通过同样的解非线性方程组和分片二次插值,
*
)
y 的函数值,进而通过满足精度的k 和矩阵c ,计算出
j
(
p x
i
(
f x
i
计算出
y
)
,
,
*
*
*
j
的值,比较二者,即可观察到逼近的效果。
二、 源程序
#include
#include
#include
#include
using namespace std;
#define N 4
#define Eps 1.0e-12
int IteNewton(double x[N], double x1, double y1);
double vNorminf(double x[N]);
void Doolittle(double a[N][N], double b[N], double x[N]);
double Interp2(double x0[6],double y0[6],double z[6][6],double x,double y);
void matInverse(double *in, double *out, int n);
void matTranspose(double *in, double *out,int m, int n);
void matMultiply(double *a, double *b, double *c, int m, int s, int n);
//分片二次插值
int main()
{
double a[N];
int i,j,k,r,s;
double x[11],y[21];
double f[11][21];
double u[11][21],t[11][21],P[8][5];
double z[6][6]={{-0.5,-0.34,0.14,0.94,2.06,3.5},
{-0.42,-0.5,-0.26,0.3,1.18,2.38},
{-0.18,-0.5,-0.5,-0.18,0.46,1.42},
{0.22,-0.34,-0.58,-0.5,-0.1,0.62},
{0.78,-0.02,-0.5,-0.66,-0.5,-0.02},
{1.5,0.46,-0.26,-0.66,-0.74,-0.5}
};
double u0[6]={0,0.4,0.8,1.2,1.6,2};
double t0[6]={0,0.2,0.4,0.6,0.8,1};
double sigma=0;
double _x[8],_y[5],_f[8][5],_t[8][5],_u[8][5];
for(i=0;i<11;i++)
x[i]=0.08*i;
for(i=0;i<21;i++)
y[i]=0.5+0.05*i;
for(i=0;i<11;i++)
for(j=0;j<21;j++)
{
}
IteNewton(a, x[i], y[j]);
t[i][j]=a[0];
u[i][j]=a[1];
for(i=0;i<11;i++)
for(j=0;j<21;j++)
f[i][j]=Interp2(u0,t0,z,u[i][j],t[i][j]);
ofstream outfile("result.txt");
if (!outfile)
{
cout<<"error";
exit(1);
}
outfile.setf(ios::scientific);
outfile.precision(12);
for(i=0;i<11;i++){
for(j=0;j<21;j++)
outfile<
Gt=new double[21*(k+1)];
Bu=new double[21*(k+1)];
Bug=new double[(k+1)*(k+1)];
for(i=0;i<11;i++)
for(j=0;j
delete []Gt;
delete []Bu;
delete []Bug;
if(sigma<=1.0e-7){
outfile<
for(i=0;i<8;i++)
for(j=0;j