Source Code Bisection Method C++ - Review Gadget Terbaru Fajar Nugraha Wahyu

Breaking

Saturday 9 July 2016

Source Code Bisection Method C++

#include<iostream>
#include<conio.h>
#include<math.h>
#define e 2.718281828

using namespace std;



float mencarief(float x)
{
float d;
d=pow(e,x) -2 - pow(x,2);
return d;
}

float mencarixr(float x1, float x2, float tempfi, float tempfu){
    float inixr;
    inixr=x1-tempfi * (x2 - x1)/(tempfu - tempfi); //a - F_a * (b - a) / (F_b - F_a);
    return inixr;
}

float banding (float fi, float fr){
    if((fi*fr)<0){
        return 0; //xu=xr
    }else{
        return 1; //xi=xr
    }
}

float mencariE(float xii, float xrr){
    float Ea = (xrr-xii)/xrr;
    return Ea;
}

main(){
    float xi, xr, xu, Ea=100;
    float tempxi, tempxu, tempfi, tempfr, tempfu;
    float perbandingan;
    int n=0;
    float arrayEa[n];
    arrayEa[0]=0.01;
    cout<<"\n\t\t\t\t METODE BISECTION\n";
    cout<<"\t\t\t\t METODE BAGI DUA \n";
    cout<<"\t\t\t\t ****************\n\n";
    cout<<"masukkan xi = ";cin>>xi;
    cout<<"masukkan xu = ";cin>>xu;
   
    while(tempfr>=0.01){               
       
        tempfi = mencarief(xi);
        tempfu = mencarief(xu);
        xr = mencarixr(xi, xu);
        cout<<xi<<"\t";
        cout<<xr<<"\t";
        cout<<xu<<"\t";
        tempfr = mencarief(xr);
        cout<<tempfi<<"\t";
        cout<<tempfr<<"\t";
        cout<<tempfu<<"\t";
               
        //Baris berikutnya
        perbandingan = banding(tempfi, tempfr);
        if(perbandingan==0){
            xu=xr;
        }else{
            xi=xr;
        }
        xr=mencarixr(xi, xu);
       
        Ea=mencariE(xi, xr);
        cout<<arrayEa[n]<<"\n";
        arrayEa[n+1]=Ea;
        n++;
    }
    cout<<"\n\t\t\t\t\t\t\tTERIMA KASIH";
cout<<"\n\t\t\t\t\t\t\t*************";
cout<<"\n\t\t\t\t\t\t\tFajar Nugraha Wahyu";
}


No comments:

Post a Comment