Jaccobi_solution.cpp
上传用户:jinqiu1010
上传日期:2021-09-06
资源大小:3082k
文件大小:1k
源码类别:
能源行业(电力石油煤炭)
开发平台:
C/C++
- // Jaccobi_solution.cpp : Defines the entry point for the console application.
- //
- #include "stdafx.h"
- //#include"P_Q_solution.cpp"
- #define n 2
- int main(int argc, char* argv[])
- {
- int i,j;
- float P[n]={1,1.5};
- float Q[n]={1,2};
- float e[n]={1,1};
- float f[n]={0};
- float G[n][n]={{2,2},{1.5,20}},B[n][n]={{0.2,2.5},{0.15,2}};
- float Jac[2*n][2*n];
- //void P_Q(P[n],Q[n],e[n],f[n],G[n],B[n]);
- for(i=0;i<n;i++)
- {
- for(j=0;j<n;j++)
- {
- if(j!=i)
- {
- float a=0.0,b=0.0;
- a=(G[i][j]*e[i]+B[i][j]*f[i]);
- b=(B[i][j]*e[i]-G[i][j]*f[i]);
- Jac[2*i][2*j]=0.0-a;
- Jac[2*i][2*j+1]=b;
- Jac[2*i+1][2*j]=b;
- Jac[2*i][2*j+1]=a;
- }
- else
- {
- float sum1=0.0;
- float sum2=0.0;
- int k;
- for(k=0;k<n;k++)
- {
- sum1=sum1+(G[i][k]*e[k]-B[i][k]*f[k]);
- sum2=sum2+(B[i][k]*e[k]+G[i][k]*f[k]);
- }
- Jac[2*i][2*j]=0.0-sum1-G[i][i]*e[i]-B[i][i]*f[i];
- Jac[2*i][2*j+1]=0.0-sum2+B[i][i]*e[i]-G[i][i]*f[i];
- Jac[2*i+1][2*j]=sum2+B[i][i]*e[i]-G[i][i]*f[i];
- Jac[2*i+1][2*j+1]=0.0-sum1+G[i][i]*e[i]+B[i][i]*f[i];
- }
- }
- }
- printf("nJaccobi矩阵是:n");
- for(i=0;i<2*n;i++)
- {
- for(j=0;j<2*n;j++)
- {
- printf("%f",Jac[i][j]);
- printf(" ");
- }
- printf("n");
- }
- return 0;
- }