HydroCODE_1D
0.1
This is a implementation of fully explict forward Euler scheme for 1-D Euler equations of motion on Lagrangian/Eulerian coordinate
math_algo.c
浏览该文件的文档.
1
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <math.h>
9
10
19
int
rinv
(
double
a[],
const
int
n)
20
{
21
int
*is,*js,i,j,k,l,u,v;
22
double
d,p;
23
is=malloc(n*
sizeof
(
int
));
24
js=malloc(n*
sizeof
(
int
));
25
for
(k=0; k<=n-1; k++)
26
{
27
d=0.0;
28
for
(i=k; i<=n-1; i++)
29
for
(j=k; j<=n-1; j++)
30
{
31
l=i*n+j;
32
p=fabs(a[l]);
33
if
(p>d)
34
{
35
d=p;
36
is[k]=i;
37
js[k]=j;
38
}
39
}
40
if
(d+1.0==1.0)
41
{
42
free(is);
43
free(js);
44
fprintf(stderr,
"Error: no inverse matrix!\n"
);
45
return
0;
46
}
47
if
(is[k]!=k)
48
for
(j=0; j<=n-1; j++)
49
{
50
u=k*n+j;
51
v=is[k]*n+j;
52
p=a[u];
53
a[u]=a[v];
54
a[v]=p;
55
}
56
if
(js[k]!=k)
57
for
(i=0; i<=n-1; i++)
58
{
59
u=i*n+k;
60
v=i*n+js[k];
61
p=a[u];
62
a[u]=a[v];
63
a[v]=p;
64
}
65
l=k*n+k;
66
a[l]=1.0/a[l];
67
for
(j=0; j<=n-1; j++)
68
if
(j!=k)
69
{
70
u=k*n+j;
71
a[u]=a[u]*a[l];
72
}
73
for
(i=0; i<=n-1; i++)
74
if
(i!=k)
75
for
(j=0; j<=n-1; j++)
76
if
(j!=k)
77
{
78
u=i*n+j;
79
a[u]=a[u]-a[i*n+k]*a[k*n+j];
80
}
81
for
(i=0; i<=n-1; i++)
82
if
(i!=k)
83
{
84
u=i*n+k;
85
a[u]=-a[u]*a[l];
86
}
87
}
88
for
(k=n-1; k>=0; k--)
89
{
90
if
(js[k]!=k)
91
for
(j=0; j<=n-1; j++)
92
{
93
u=k*n+j;
94
v=js[k]*n+j;
95
p=a[u];
96
a[u]=a[v];
97
a[v]=p;
98
}
99
if
(is[k]!=k)
100
for
(i=0; i<=n-1; i++)
101
{
102
u=i*n+k;
103
v=i*n+is[k];
104
p=a[u];
105
a[u]=a[v];
106
a[v]=p;
107
}
108
}
109
free(is); free(js);
110
return
1;
111
}
rinv
int rinv(double a[], const int n)
A function to caculate the inverse of the input square matrix.
Definition:
math_algo.c:19
tools
math_algo.c
制作者
1.9.3