a=0
b=2
n=256
h=(b-a)/n
x=a
sigmaganjil=0
sigmagenap=0
in1= ((4*0)-(0^3))*exp(0^2)
printf('%2d \t %11.6f \t %11.6f \n',1,a,in1);
for i=1:n-1;
x=x+h
fr=((4*x)-(x^3))*exp(x^2)
printf('%2d \t %11.6f \t %11.6f \n',i,x,fr);
if modulo(i,2) ==0 then
sigmagenap=sigmagenap+2*((4*x)-(x^3))*exp(x^2)
else
sigmaganjil=sigmaganjil+4*((4*x)-(x^3))*exp(x^2)
end
end
inakhir= ((4*2)-(2^3))*exp(2^2)
printf('%2d \t %11.6f \t %11.6f \n',n,2,inakhir);
jumlah=(in1+sigmaganjil+sigmagenap+inakhir)/3
disp("Hasil perhitungan simpson=")
printf('%11.6f',jumlah)
0 comments :
Post a Comment