typedef struct
{
double **p
int rows
int cols
}MATRIX
MATRIX matrix_inverse(MATRIX matrix)
void sweep(MATRIX matrix)
MATRIX create(int rows,int cols)
MATRIX multiply(MATRIX matrix1,MATRIX matrix2)
MATRIX buildmatrix(MATRIX matrix)
MATRIX input(MATRIX matrix)
void printmatrix(MATRIX matrix)
int main()
{
int n
MATRIX A,b
printf("Please input the dimension of the liner equations\n")
scanf("%d",&n)
printf("Please input the quotiety of the eqaution\n")/*输入方程的系数矩阵.*/
A=create(n,n)
input(A)
b=create(n,1)
printf("请输入方程右边的数字\n")
input(b)
printf("The resullt is:\n")
printmatrix(multiply(matrix_inverse(A),b))
system("pause")
return 0
}
MATRIX matrix_inverse(MATRIX matrix)
{
int i,j,k,m
MATRIX temp,result
double *p,rate
if(matrix.rows!=matrix.cols||matrix.p==NULL)
{
printf("Error: This matrix has no inverse,because it's rows doesn't equal columns" )
printf(" or the matrix dosen't exist\n")
temp=create(0,0)
return temp
}
temp=buildmatrix(matrix)
for(i=0i<temp.rows-1++i)
{
if(temp.p[i][i]<=1e-14)
{
for(m=i+1m<temp.rows++m)
{
if(temp.p[m][i]>1e-14)
{
p=temp.p[i]
temp.p[i]=temp.p[m]
temp.p[m]=p
break
}
else
continue
}
if(m==temp.rows)
{
printf("Error: This matrix has no inverse,because it's determinant equals zero\n" )
sweep(temp)
temp=create(0,0)
return temp
}
else
}
else
for(j=i+1j<temp.rows++j)
{
rate=temp.p[j][i]/temp.p[i][i]
for(k=i+1k<temp.cols++k)
temp.p[j][k]-=rate*temp.p[i][k]
}
}
if(temp.p[temp.rows-1][temp.rows-1]<=1e-14)
{
printf("Error: This matrix has no inverse,because it's determinant equals zero\n" )
temp=create(0,0)
return temp
}
for(i=temp.rows-1i>0--i)
for(j=0j<i++j)
{
rate=temp.p[j][i]/temp.p[i][i]
for(k=temp.rowsk<temp.cols++k)
temp.p[j][k]-=rate*temp.p[i][k]
}
for(i=0i<temp.rows++i)
for(j=temp.rowsj<temp.cols++j)
temp.p[i][j]*=1.0/temp.p[i][i]
result=create(matrix.rows,matrix.cols)
for(i=0i<temp.rows++i)
for(j=matrix.colsj<temp.cols++j)
result.p[i][j-matrix.cols]=temp.p[i][j]
sweep(temp)
return result
}
void sweep(MATRIX matrix)
{
int i
for(i=0i<matrix.rows++i)
free(matrix.p[i])
free(matrix.p)
}
MATRIX create(int rows,int cols)
{
int i
MATRIX result
if(rows>0&&cols>0)
{
result.p=(double**)malloc(rows*sizeof(double*))
result.rows=rows
result.cols=cols
for(i=0i<rowsi++)
result.p[i]=(double*)malloc(cols*sizeof(double))
}
else
{
result.p=NULL
result.rows=0
result.cols=0
}
return result
}
MATRIX multiply(MATRIX matrix1,MATRIX matrix2)
{
int x,y,k
MATRIX matrix
if(matrix1.p==NULL||matrix2.p==NULL)
{
printf("Error:One or two matrixes not exist\n")
matrix=create(0,0)
return matrix
}
else if(matrix1.cols==matrix2.rows)
{
matrix=create(matrix1.rows,matrix2.cols)
for(x=0x<matrix1.rows++x)
for(y=0y<matrix2.cols++y)
*(*(matrix.p+x)+y)=0.00
for(x=0x<matrix1.rows++x)
for(y=0y<matrix2.cols++y)
for(k=0k<matrix1.cols++k)
matrix.p[x][y]+=matrix1.p[x][k]*matrix2.p[k][y]
return matrix
}
else if(matrix2.cols==1&&matrix2.rows==1)
{
matrix=create(matrix1.rows,matrix1.cols)
for(x=0x<matrix1.rows++x)
for(y=0y<matrix1.cols++y)
matrix.p[x][y]=matrix1.p[x][y]*matrix2.p[0][0]
return matrix
}
else if(matrix1.cols==1&&matrix1.rows==1)
{
matrix=create(matrix2.rows,matrix2.cols)
for(x=0x<matrix2.rows++x)
for(y=0y<matrix2.cols++y)
matrix.p[x][y]=matrix2.p[x][y]*matrix1.p[0][0]
return matrix
}
else
{
printf("The two matrixes can't be multipled\n")
matrix=create(0,0)
return matrix
}
}
MATRIX buildmatrix(MATRIX matrix)
{
MATRIX temp
int i,j
temp=create(matrix.rows,2*matrix.cols)
for(i=0i<temp.rows++i)
for(j=0j<matrix.cols++j)
temp.p[i][j]=matrix.p[i][j]
for(i=0i<temp.rows++i)
for(j=matrix.colsj<temp.cols++j)
{
if(j-i==matrix.cols)
temp.p[i][j]=1.0
else
temp.p[i][j]=0.0
}
return temp
}
MATRIX input(MATRIX matrix)
{
int i,j
for(i=0i<matrix.rows++i)
for(j=0j<matrix.cols++j)
scanf("%lf",(*(matrix.p+i)+j))
return matrix
}
void printmatrix(MATRIX matrix)
{
int i,j
if(matrix.p!=NULL)
for (i=0i<matrix.rows++i)
{
for (j=0j<matrix.cols++j)
printf("%-g\t",matrix.p[i][j])
printf("\n")
}
else
{
printf("Error:The matrix dosen't exist!\n")
return
}
}
dfgf(gvgv)hyd-==dshgcf_dhf{{{nhfjr_jdb+jjhfbb=jej
}
ndsj"""
smslkjjjjjjjjjjejbur-lkdj=ddda
{skncvfhvb
ej
::}
so
freemarker文件还是html代码占多数,即使是freemarker代码,也会经过服务器翻译成html代码返回到浏览器端,所以说,你可以在freemarker文件里,直接用html的语法引入CSS和JS。说白了,freemarker只是辅助你写html文件而已,你当做写html文件就行了,不用想那么复杂。
如下代码,只有标记到的地方是freemarker语法,其余都是html语法
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<!-- 这句是freemaker -->
<title>${webSite.title!}</title>
<!-- 这句的base是freemaker,其余不是 -->
<script src="${base}/resource/plugin/require/require.js"></script>
</head>
<body>
<!-- 这句的user.name是freemaker,其余不是 -->
<h1>欢迎您,${user.name}</h1>
<!-- 这句是freemaker -->
<#include "body.html">
</body>
</html>