loading...
مرجع مهندسی نرم افزار
آخرین ارسال های انجمن
حامد شیرزاد بازدید : 1081 شنبه 28 آبان 1390 نظرات (0)
عزیزانی که درس محاسبات عددی روگذرونده باشند با این روش ها آشنایی دارند. در اینجا کد پیاده سازی این الگوریتم ها رو برای مطالعه بیشتر قرار میدم
Jacobi itterative and gauss seidal method to solve roots
 
this is a program from numerical to calculate the root of
the given system ,it will check its conditions and then perform the
operation on that system,esle it will tell u that system is not diagonally dominent 
,,,,in this program the functions used can be used in other program ,,
 
 
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<iomanip.h>
 
float a1[4],a2[4],a3[4];                       /* Array declaration */
void show();                                   /* function declaration 
*/
void getdata(float [],float [],float []);      /*    //   //    //    
*/
void display(float [],float [],float []);      /*    //   //    //    
*/
int diagonally();
void swap(float [],float []);                  /*    //   //    //    
*/
void jacobi(float [],float [],float []);       /*    //   //    //    
*/
void gauss(float [],float [],float []);
void answer();
/*^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^*
/
/*....................MAIN FUNCTION OF METHOD............*/
void main()                              /* main function definition   
*/
  {
      int  count=4;                           /* { main function body} 
*/
      clrscr();
 
cout<<"^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
^^^^^^^^^^^"<<endl;
      cout<<"..................THIS IS VALID ONLY FOR JACOBI ITTERATIVE
METHOD............."<<endl;
 
cout<<"___________________________________________________________________
___________"<<endl;
      show();                            /*  function calling  */
      getdata(a1,a2,a3);                 /*  function calling  */
      clrscr();
      cout<<endl<<endl;
      display(a1,a2,a3);                    /*  function calling  */
      count=diagonally();                   /*  function calling  */
      switch (count)
     {
      case 0:
           {
        answer();        /*  function calling */
        break;
           }
      case 2:
           {display(a1,a2,a3);
        answer();       /*  function calling */
        break;
           }
      default:
           {
        cout<<"SORRY;YOUR SYSTEM IS NOT DIAGONALLY DOMINENT";
        break;
           }
     }
 getch();
  }
////////////////////////Function To Check
Diagonality////////////////////////
int diagonally()
  {
     int f=4,g=4 ,h=4;
     int count=0;
     float temp[4];
     if(fabs(a1[0])<(fabs(a1[1])+fabs(a1[2])))
    {count++;  f=1;}
     if(fabs(a2[1])<(fabs(a2[0])+fabs(a2[2])))
    {count++;  g=2;}
     if(fabs(a3[2])<(fabs(a3[0])+fabs(a3[1])))
    {count++;  h=3;}
     if(f==1&&g==2&&h==4)
    swap(a1,a2);                           /*  function calling  */
     if(f==1&&h==3&&g==4)
    swap(a1,a3);                           /*  function calling  */
     if(g==2&&h==3&&f==4)
    swap(a2,a3);                           /*  function calling  */
 
   return(count);
  }
////////////////////////////Function for jacobi itterative
method/////////////////////////
void jacobi(float a[],float b[],float c[]) /*function definition */
  {
     float temp[3];
     long float j1,j2,j3;
     cout<<endl<<"please enter the initial guess:"<<endl;
     cout<<endl<<"X(1) =";
     cin>>j1;
     cout<<endl<<"X(2) =";
     cin>>j2;
     cout<<endl<<"X(3) =";
     cin>>j3;
 
cout<<"-------------------------------------------------------------------
----";
 
cout<<":::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::";
 
cout<<"___________________________________________________________________
____";
     cout<<endl<<endl<<"iterrations #"<<"  "<<"  X(1)"<<"
X(2)"<<"           X(3)";
     cout<<endl<<"   0"<<setw(17)<<j1<<setw(15)<<j2<<setw(14)<<j3;
     cout<<endl;
 
     for(int s=1;s<=20;s++)
     {
      temp[0]=j1;temp[1]=j2;temp[2]=j3;
      j1=(a[3]-a[1]*temp[1]-a[2]*temp[2])/a[0];
      j2=(b[3]-b[0]*temp[0]-b[2]*temp[2])/b[1];
      j3=(c[3]-c[0]*temp[0]-c[1]*temp[1])/c[2];
      cout<<"   "<<s<<setw(17)<<j1<<setw(15)<<j2<<setw(14)<<j3<<endl;
      if(j1==temp[0]&&j2==temp[1]&&j3==temp[2])
         break;
     }
  }
//////////////////////////Function Of
Swaping////////////////////////////////////
void swap(float a[],float b[])          /*  function definition   */
  {
   float temp[4];
 
cout<<"-------------------------------------------------------------------
-------------"<<endl;
درباره ما
به نام آنکه جان را فکرت آموخت در این وبلاگ سعی می شود به صورت تخصصی به مباحث مربوط به مهندسی نرم افزار به خصوص برنامه نویسی کامپیوتری پرداخته شود. مدیر وبلاگ : حامد شیرزاد
اطلاعات کاربری
  • فراموشی رمز عبور؟
  • آمار سایت
  • کل مطالب : 431
  • کل نظرات : 9
  • افراد آنلاین : 1
  • تعداد اعضا : 109
  • آی پی امروز : 68
  • آی پی دیروز : 72
  • بازدید امروز : 166
  • باردید دیروز : 81
  • گوگل امروز : 0
  • گوگل دیروز : 0
  • بازدید هفته : 497
  • بازدید ماه : 3,148
  • بازدید سال : 22,249
  • بازدید کلی : 790,777
  • کدهای اختصاصی

    قالب وبلاگ