python n元一次方程模糊解
#include <math.h>
#include <conio.h>
#include<stdio.h>
void Iteration_f(double);
int Epsilon_f (double*,double*,int,double);
void matrix_f(void);
void Initialize_f(void);
void Rearrange_f(void);
void Solve_f(double);
void ShowAnswer(void);
void Output_f(void);
void Input_f(void);
int nRow,nColumn;
double **dlpMat;
int nVarNum;
double *dlpVar;
int nIterCount;
Matrix_f(void)
python printf输出格式{
int nCounti;
/*creates my matrix dynamically, but there are still no values in the positions */
dlpMat=(double **) malloc(sizeof( double) *nRow*nColumn);
}
void Initialize_f (void)
{
printf("How many ROWS?");
scanf("%d", &nRow);
printf("How many COLUMNS?");
scanf("%d", &nColumn);
}
/**********************************
* 高斯-赛德尔矩阵变换函数 *
* rearrange function *
**********************************/
void Rearrange_f(void)
{
int nCounti, nCountj;
double dlCoeff;
nVarNum=nColumn-1;
/* 'variable' will contain the solution set */
/* they will get initialized with the first guess in the 'solve' function */
dlpVar=(double*)malloc(sizeof(double) * nVarNum);
/*divides all terms by the desired variables (the dlpVar which is being solved for) coefficient*/
for(nCounti=0;nCounti<nRow;nCounti++)
{
dlCoeff=dlpMat[nCounti][nCounti];
for(nCountj=0;nCountj<nColumn;nCountj++)
{
dlpMat[nCounti][nCountj]/=dlCoeff;
}
}
/* all variables except the diagonal are being brought to the other side */
for( nCounti=0;nCounti<nRow;nCounti++)
{
for(nCountj=0;nCountj<nColumn-1;nCountj++)
{
dlpMat[nCounti][nCountj]*=-1;
}
dlpMat[nCounti][nCounti]=0;
}
}
/***********************************
* iteration funtion--迭代函数 *
***********************************/
void Iteration_f(double dlLambda)
{
int nCounti, nCountj;
/* 'last' is for the relaxation equation */
double dlLast;
for(nCounti=0;nCounti<nVarNum;nCounti++)
{
dlLast=dlpVar[nCounti];
dlpVar[nCounti]=0;
for( nCountj=0;nCountj<nVarNum;nCountj++)
{
dlpVar[nCounti]+=dlpMat[nCounti][nCountj]*dlpVar[nCountj];
}
dlpVar[nCounti]+=dlpMat[nCounti][nColumn-1];
/* new value after relaxation */
dlpVar[nCounti]=dlLast+dlLambda *(dlpVar[nCounti]-dlLast);
}
}
/*********************************
* solve function--求解函数 *
*********************************/
void Solve_f(double dlLambda)
{
double dlCriterion;
int nCounti, nCountj;
double *dlpNew, *dlpLast;
for (nCounti=0;nCounti<nVarNum;nCounti++)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论