Random Post

Home » » Contoh Program C++ Newton Raphson

Contoh Program C++ Newton Raphson

Berikut adalah skrip dari proram newton raphson :

#include <iostream>
#include <conio>
#include <math>

main(){
float ar_x [105];
float ar_fx [105];
float ar_fx1 [105];
float ar_galat [105];
double angka_awal;
double batas_galat;
cout<<" fungsi : x^2-4";
cout<<"\nmasukan angka awal : ";
cin >>angka_awal;
cout<<"\nmasukan batas galat : ";
cin>>batas_galat;

clrscr();
gotoxy (1,1);cout<<"iterasi";
gotoxy(20,1);cout<<"x";
gotoxy(40,1);cout<<"f(x)";
gotoxy(60,1);cout<<"f(x)'";
gotoxy(70,1);cout<<"galat";
int i;
for(i = 2;i<=102;i++)
{
if (i == 102){
cout<<endl;
}
 gotoxy(1,i);cout<<(i-1);

 if (i == 2){
 int a,b;
gotoxy(20,i);
cout<<angka_awal;
ar_x[i]= angka_awal;
gotoxy(40,i);
 a=((angka_awal*angka_awal)-4);
 cout<<a;
  ar_fx[i]=a ;

gotoxy(60,i);
b=(2*angka_awal);
cout<<b;
ar_fx1[i]=b;
gotoxy(70,i);cout<<"-";
 }
 else {
 float c,d,e,f;
    c= 0;
    d = 0;
    e = 0;
    f = 0;
gotoxy(20,i);
c=(ar_x[i-1]-(ar_fx[i-1]/ar_fx1[i-1]));
cout<<c;
ar_x[i] = c;
gotoxy(40,i);
d=((ar_x[i]*ar_x[i])-4);
cout<<d;
ar_fx[i]=d;
gotoxy(60,i);
e=(2*(ar_x[i]));
cout<<e;
ar_fx1[i]=e;
gotoxy(70,i);
f =((ar_x[i]- ar_x[i-1])/ar_x[i]);

if (f < 0){
float k;
k= (f*(-1));
f = 0;
f = k;
}
cout<< f;
ar_galat[i]=f;


   }
   if (i != 2){
   if(ar_galat[i]< batas_galat){
   i=102;
   }
   else if(ar_fx1[i] == 0){
   i = 102;
   }

   }

}
getch();





Semoga bermanfaat..
}
Share this article :

0 komentar:

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Aura Cerdas - All Rights Reserved
Template Modify by Creating Website
Proudly powered by Blogger