Home » , , » Program C++ Regula Falsi Method (Metode Regula-Falsi)

Program C++ Regula Falsi Method (Metode Regula-Falsi)

Posted by RZDev: Belajar Programming! on Saturday, October 21, 2017


Berikut contoh program menghitung dengan Regula Falsi metode numerik.

#include<iostream>
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<process.h>

using namespace std;

// Deklarasi Formulanya
#define EPS 0.00001
#define f(x)  (pow(2.718,-x)-x)
int n;

void FAL_POS();

int main()
{

cout <<"Metode Regula-Falsi "<< endl;
cout <<"Equation is -> f(x)=(e^-x)-x "<< endl;
cout <<"Masukkan Iterasi Maximum  : "; cin  >> n;

FAL_POS();
getch();
}

void FAL_POS()
 {
float x1,x2,x0;
 float f1,f2,f0;
 int itr=n,i;
 for(x1=0.0;;)
    {
    f1=f(x1);
    if(f1>0)
      break;
    else
      x1=x1+0.1;
    }
 x0=x1-0.1;
 f0=f(x0);
 printf("\n----------------------------------------------------");
 printf("\n ITERATION\t x2\t\t\t   F(X)\n");
 printf("\n----------------------------------------------------\n");
 for(i=0;i<itr;i++)
    {
    x2=x0-((x1-x0)/(f1-f0))*f0;
    f2=f(x2);
    if(f0*f2>0)
      {
      x1=x2;
      f1=f2;
      }
    else
      {
      x0=x2;
      f0=f2;
      }
    if(fabs(f(2))>EPS)
      printf("\n %d \t %.7f \t %.7f ",i+1,x2,f2);
    }
 printf("\n----------------------------------------------------");
 printf("\n Result  = %.10f ",x2);
 printf("\n----------------------------------------------------");
}

Sekian script C++ untuk Regula-Falsi Method, jika ada yang ingin ditanyakan bisa melaui komentar dibawah ini atau langsung menghubungi saya melalui contact person yang ada. Terima Kasih & Semoga Bermanfaat

Thanks for reading & sharing RZDev: Belajar Programming!

Previous
« Prev Post

0 comments:

Post a Comment

Search