Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
雅可比迭代法.cpp
Package: shuzhi_C++.rar [view]
Upload User: hks123456
Upload Date: 2014-01-27
Package Size: 18k
Code Size: 1k
Category:
Algorithm
Development Platform:
Visual C++
- #include<iostream.h>
- #include<math.h>
- #define EPS 1e-6
- #define MAX 100
- float *Jacobi(float a[3][4],int n)
- {
- float *x,*y,epsilon,s;
- int i,j,k=0;
- x =new float[(n*sizeof(float))]; //here must be modifed
- y =new float[(n*sizeof(float))]; //here must be modifed
- for( i=0;i<n;i++ )
- x[i]=0;
- while(1)
- {
- epsilon=0;
- k++;
- for( i=0;i<n;i++ )
- {
- s=0;
- for( j=0;j<n;j++ )
- {
- if(j==i)
- continue;
- s+=a[i][j]*x[j];
- }
- y[i] =(a[i][n]-s)/a[i][i];
- epsilon +=fabs(y[i]-x[i]);
- }
- if(epsilon<EPS)
- {
- cout<<"迭代次数为:"<<k<<endl;
- return y;
- }
- if( k>=MAX )
- {
- cout<<"The method is disconvergent";
- return y;
- }
- for( i=0;i<n;i++ )
- x[i]=y[i];
- }
- return y;
- }
- void main()
- {
- int i;
- float a[3][4]={5.0,2.0,1.0,8.0,2.0,8.0,-3.0,21.0,1.0,-3.0,-6.0,1.0}; //here must be modifed
- float *x;
- x=new float[(3*sizeof(float))]; //here must be modifed
- x=Jacobi(a,3);
- for( i=0;i<3;i++ )
- cout<<"x["<<i<<"]="<<x[i]<<endl;
- }