-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsolves.c
More file actions
executable file
·33 lines (28 loc) · 951 Bytes
/
solves.c
File metadata and controls
executable file
·33 lines (28 loc) · 951 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
void solve_system(up,low,gamma,l,rhs,d)
/* solve tridiagonal linear system
of size (l+1)(l+1) whose LU decompostion has entries up and low,
and whose right hand side is rhs, and whose original matrix
had upper diagonal gamma. Solution is d[0],...,d[l+2];
Input: up,low,gamma: as above.
l: size of system: l+1 eqs in l+1 unknowns.
rhs: right hand side, i.e, data points with end
`tangent Bezier points' in rhs[1] and rhs[l+1].
Output:d: solution vector.
Note: Both rhs and d are from 0 to l+2.
*/
float up[],low[],gamma[],rhs[],d[];
int l;
{
int i;
float aux[100];
d[0] = rhs[0];
d[1] = rhs[1];
/* forward substitution: */
aux[0]=rhs[1];
for(i=1; i<=l; i++) aux[i]=rhs[i+1]-low[i]*aux[i-1];
/* backward substitution: */
d[l+1]=aux[l]/up[l];
for(i=l-1; i>0; i--) d[i+1]=(aux[i]-gamma[i]*d[i+2])/up[i];
d[l+2]=rhs[l+2];
}