- #1
Lengalicious
- 163
- 0
Homework Statement
Ok for starters, I wasn't entirely sure whether this was supposed to go under physics or comp sci, this is a 'physics' problem I believe but done through visual basic, anyways.
So I have a program where the Earth is animated to orbit the sun based on Newtons laws, I need to calculate the definite integral from X = start of orbit, to X = 0 ∫ Y(x) dx based on the linear interpolation formula shown below.
Homework Equations
Extended linear interpolation formula: 1/2*(f(x1) + f(x2))*h + 1/2*(f(x3) + f(x4))*h + . . + 1/2*(f(xn-1) + f(xn))*h
where h is supposed to be x2-x1 for the 1st term then x3-x2 for the next term etc.
The Attempt at a Solution
Please note that before this question I had a question to integrate ∫ 1/R(t)2 dt from where the Earth starts to X=0 before the one I'm asking and I achieved this by doing a sum within the While loop, ie.
Code:
While x > 0
Sum = Sum + Function
End While
Then taking away the 1/2*(1st + last) terms to adjust for the error in the extended interpolation formula.
Now for the question I'm completely stuck all I can suggest to myself is doing another summation during the loop of the function 'Y' but then I have to somehow adjust the answer so that it gives the same answer as the formula but I don't understand how to multiply each term by 'h' in visual basic? Any suggestions?