„ Metode selisih tengahan merupakan metode pengambilan perubahan dari dua titik sekitar dari titik yang diukur. „
- Perhatikan selisih maju pada titik x-h
![]() |
metode selisih maju |
„ 2. selisih maju pada titik x
selisih maju titik x |
„ 3. Metode selisih tengahan merupakan rata-rata dari dua selisih maju :
rumus metode selisih tengahan |
nah untuk komputasi di komputer nya gunakan kode program berikut ini.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
differensial selisih TENGAH | |
*/ | |
#include"stdio.h" | |
#include"math.h" | |
double a,b,x,ft,fek,fx,error,sigma=0,total_error,h; | |
int i=0; | |
double f(double x) | |
{ | |
return(exp(-x)*sin(2*x)+1); | |
} | |
double f_eksak(double x) | |
{ | |
return(-exp(-x)*sin(2*x)+exp(-x)*2*cos(2*x)); | |
} | |
double fungsi_tengah(double x,double h) | |
{ | |
return((f(x+h)-f(x-h))/(2*h)); | |
} | |
void tengah() | |
{ | |
printf("masukan batas atas="); | |
scanf("%lf",&b); | |
printf("masukan batas bawah="); | |
scanf("%lf",&a); | |
printf("masukan nilai step h= "); | |
scanf("%lf",&h); | |
puts("=========================================================================="); | |
printf("%s\t %8s\t %8s\t %8s\t %8s\n\n","x","f(x)","f'(x)","eksak","error"); | |
puts("=========================================================================="); | |
for(x=a;x<=b;x+=h) | |
{ i++; | |
fx=f(x); | |
ft=fungsi_tengah(x,h); | |
fek=f_eksak(x); | |
error=fabs(fek-ft);//mencari error | |
printf(" %g \t %8lf \t %8lf \t %8lf \t %8lf\n",x,fx,ft,fek,error); | |
sigma=sigma+error; | |
} | |
total_error=sigma/i;//rata-rata error | |
printf("\nRata-rata error = %lf\n",total_error); | |
} | |
main() | |
{ puts("\t===================="); | |
puts("\t DIFFERENSIAL"); | |
puts("\tMetode selisih tengah"); | |
puts("\t====================\n\n"); | |
tengah(); | |
} |