1

I was carrying out a function and ended up with the desired answer, but for some reason, Mathematica keeps giving me the answer in a strange numerical form.

SIMP[a_, b_, n_] := (1/3)[(b - a)/n][
  Sum[f[a + (2 x - 2) (b - a)/n] + 4 f[a + (2 x - 1) (b - a)/n] + 
    f[a + 2 x (b - a)/n], {x, 1, n/2}]]

SIMP[0, 2, 8]
(* (1/3)[1/4][
 f[0] + 4 f[1/4] + 2 f[1/2] + 4 f[3/4] + 2 f[1] + 4 f[5/4] + 
  2 f[3/2] + 4 f[7/4] + f[2]] *)

Clear[f]
f[x_] := 1/(1 + x^6)
SIMP[0, 2, 8]
(* (1/3)[1/4][557032465187652359/44540986037769325] *)

All I need is for the output to turn into a numerical value with 6 decimal places, but it stays in this form. Any advice?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Brian
  • 13
  • 2

1 Answers1

3
ClearAll[f,sIMP];
sIMP[a_, b_, n_] := (1/3) ((b - a)/n) 
          Sum[ f[a + (2 x - 2) (b - a)/n] + 4 f[a + (2 x - 1) (b - a)/n] + 
               f[a + 2 x (b - a)/n], {x, 1, n/2}]
f[x_] := 1/(1 + x^6)
sIMP[0, 2, 8] // N

(* 1.0421720807799113` *)
Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453