Mengapa perlu Metode Numerik ?
- „Terkadang terdapat suatu fungsi yang sulit dihitung secara manual
- „Untuk mengotomatiskan, tanpa harus menghitung manualnya
DIFFERENSIASI NUMERIK
„ Hubungan antara nilai fungsi dan perubahan fungsi untuk setiap titiknya didefinisikan :
„ y = f(X) + f^1(x).h(x)
rumus diferensiasi numerik |
- „Metode Selisih Maju
- „Metode Selisih Tengahan
- „Metode Selisih Mundur
nah setelah saya sedikit membahas tentang metode apa saja yang ada di diferensiasi sekarang kita belajar langsung komputasi numeriknya yang ada di komputer langsung coding mania :) hehehe.
1. kode program Diferensiasi Selisih Maju
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(); | |
} |
outputnya nanti hasilnya seperti ini dan coba angkanya untuk mengetahui benar tidak program kita angkanya gunakan dengan contoh output berikut ini .
output selisih maju |
semoga manfaat untuk 2 metode lainnya akan saya sambung di postingan selanjutnya :D