Question: A maple/maths question to be answered by YOU ;-)


 \int_{a}^{b} f(x) \, dx \approx \tfrac{3h}{8}\left[f(x_0) + 3f(x_1) + 3f(x_2) 
+ 2f(x_3) + 3f(x_4) + 3f(x_5) + 2f(x_6) + ... + f(x_n)\right] .


A Fantastic Good morning Ladies and Gentelmen,

You have the mission to find the problem in that code/ give a better code?
I want to write a procedure for the simpson 3/8 rule using the above formula I took from wikipedia :
(I don't want to use any super maple command that estimate the simpson 3/8, but just using this formula and starting from scratch, I am a beginner so feel free to laugh at my code hehehe)
here is the code I managed to write after 365 hours :D

restart:
simp38:=proc(f,x0,xn,n)                 
     local h,summ,i,x,Integral:                                              
     h=evalf((xn-x0)/n);               #h is the distance between 2 points
     summ:=f(x0)+f(xn);              #initialise the summ
    
      for i from 1 to n-1 by 3 do             
          x[i]:=x0+i*h:
          summ:=evalf(summ+3*f(x[i])):
      od:
      for i from 2 to n-1 by 3 do              
          x[i]:=x0+i*h:
          summ:=evalf(summ+3*f(x[i])):
      od:
      for i from 3 to n-1 by 3 do                  
          x[i]:=x0+i*h:
          summ:=evalf(summ+2*f(x[i])):  
      od:
    
      Integral:=3*h/8*summ;                  
 end:

simp38(x->(x^5-5.15*x^2+8.55*x-4.05045),1,5,6);   #testing it      --->2481.087090
evalf(int(x^5-5.15*x^2+8.55*x-4.05045,x=1..5));      #comparing it --->2477.531533


Your help will be apreciated.


Please Wait...