বুধবার, ১৫ জুন, ২০১১

Jacobi iterative method and gausses elimination method by C

Jacobi method:




#include"stdio.h"
#include"conio.h"
#include"iostream.h"

    void main()
    {
    clrscr();
    float a1,a2,a3,b1,b2,b3,c1,c2,c3,k1,k2,k3,x,y,z,n;
    cout<<"enter the value of this constant=";
    cin>>a1>>b1>>c1>>k1>>a2>>b2>>c2>>k2>>a3>>b3>>c3>>k3;
    cout<<"how many time do u want to calculate=";
    cin>>n;

    float x1=0,y1=0,z1=0;
    float x2,y2,z2;

    for(int i=0;i<n;i++)
    {

     x2=((1/a1)*(k1-(b1*y1)-(c1*z1)));
     y2=((1/b2)*(k2-(a2*x1)-(c2*z1)));
     z2=((1/c3)*(k3-(a3*x1)-(b3*y1)));
     cout<<"serial no="<<i<<endl;
     cout<<x2<<endl<<y2<<endl<<z2<<endl;
     x1=x2;
     y1=y2;
     z1=z2;

    }


    getch();
    }

G#include"stdio.h"
#include"conio.h"
#include"iostream.h"

    void main()
    {
    clrscr();
    float a1,a2,a3,b1,b2,b3,c1,c2,c3,k1,k2,k3,x,y,z,n;
    cout<<"enter the value of this constant=";
    cin>>a1>>b1>>c1>>k1>>a2>>b2>>c2>>k2>>a3>>b3>>c3>>k3;
    cout<<"how many time do u want to calculate=";
    cin>>n;

    float x1=0,y1=0,z1=0;

    for(int i=0;i<n;i++)
    {

     x1=((1/a1)*(k1-(b1*y1)-(c1*z1)));
     y1=((1/b2)*(k2-(a2*x1)-(c2*z1)));
     z1=((1/c3)*(k3-(a3*x1)-(b3*y1)));
     cout<<"serial no="<<i<<endl;
     cout<<x1<<endl<<y1<<endl<<z1<<endl;

    }


    getch();
    }ausses elimination method :



কোন মন্তব্য নেই:

একটি মন্তব্য পোস্ট করুন