|
According to simpsons 3/8 rule there must be atleast 3 intervals which means atleast 4 values of x. If n is the no of intervas If the user enters n<3 give an error mess and exit. If n>=3 except x's upto n+1 Tell the user to enter the function y(see note). then calculate y0,y1,.....yn[use arrays] The rule says that xn ⌡ y dx=3h/8[y0+3y1+3y2+2y3+....+2yn-3+3yn-2+3yn-1+yn] x0
[⌠-Integration] to do this you have to have an array with values [1,3,3,2] go on multiplying them to y0,y1,...yn-4 in a cyclic loop. Then do this 2yn-3+3yn-2+3yn-1+yn and add them all. so you will be getting the sum in the bracket. you know h(accept it from user). Hence you will get the result. [ Note:- when you get the function y from user store it in a string. You need to write a evaluation tree to find the values of y0,y1,..yn for the values of x0,x1,..xn ]
This post has been edited by poke_blade: 2 May, 2006 - 11:40 PM
|