#include #include #include "arrays.hpp" /* dynamic memory allocation routines */ int LUfactor1(double **A,int n); void LUsolve1(double **A,double *b,int n); int LUfactor(double **A,int *P,int n); void LUsolve(double **A,int *P,double *b,int n); main() { double **A; double *b; int *P; int n; int i,j,k; n=4; b=vector(n); /* allocate matrix/vector memory */ A=matrix(n,n); A[0][0]=1.0; A[0][1]=4.0; A[0][2]=5.0; A[0][3]=6.0; A[1][0]=1.0; A[1][1]=1.0; A[1][2]=1.0; A[1][3]=1.0; A[2][0]=3.0; A[2][1]=4.0; A[2][2]= -1.0; A[2][3]=4.0; A[3][0]=6.0; A[3][1]=4.0; A[3][2]=3.0; A[3][3]=3.0; b[0]=1.0; b[1]=1.0; b[2]=1.0; b[3]=1.0; /*----------------------------factor,solve--------*/ LUfactor1(A,n); LUsolve1(A,b,n); /*----------------------------print LU,b solution--*/ for(i=0;i=0;--i) { rowsum=0.0; for(j=n-1;j>i;--j) rowsum+=U[i][j]*x[j]; x[i]=(y[i]-rowsum)/U[i][i]; } } /* replaces b[i] vector with solution x[i] */ /*-------------------------------------------------------------------*/ int LUfactor(double **A,int *P,int n) /* factor PA=LU WITH PIVOTING */ { /* HINT : A[P[i]][j]...... */ } void LUsolve(double **A,int *P,double *b,int n)/*PA=L\U,LUx=Pb,Ly=Pb,Ux=y*/ { /* HINT: b[P[i]].... */ } /*--------------------------------------------------------------------------*/