Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X
Hi guys, I'm having a bit of trouble with this solution. I'm trying to solve a problem where in essence I'm using the RK Equation of state to find two volumes, then using the Trapezoidal Rule to "integrate" without calling an integral function. I'll attach pictures and my current Mathcad file so you can follow along with my commentary.
In the first picture I've defined the function using the Boolean operator to find by initial and final volumes. If you're using my .xmcd file be careful, I sometimes use "[" subscripts and sometimes I use p.1 instead -- click the definition to check.
In the second picture I've defined the RK equation of state as an actual function of v and I have the trapezoidal rule as a comment. I'm showing that my h = final - initial, my interval is starting from v0 and going by my step size of h/2n to my final volume. I then evaluate the RK function at the initial volume, the final volume, and sum the evaluation of p over the interval v to get the 3 terms needed for trapezoidal and I sum them to get Work.
Skipping the "Error in trapezoidal" part, I now need to make a program to double the number of steps (2*n). evaluate the work, and check if the error is less than 10^-4.
In the third picture you can see that I've done 11 iterations of doubling my step size, used the step size to get my volume interval, and used the volume interval and the 11th h term to calculate work like I did earlier.
Unfortunately, even though this gives me the correct answer, I don't think this will work for my professor. In picture 4 you can see what I'm attempting to do. I'm trying to make a function for the Work that will start with a value for n in the 1st for-loop, use the 2nd for-loop to evaluate the middle summation term for Work at that step size, use that term with p1 and p2 to calculate Work then check to see if |(W-W(old))/W| < 10^-4 and if so it'll break, but if not it'll go back and change n to n*2 and do it again. If this is confusing to read, it's also confusing to type. Sorry.
TL;DR: Trying to iterate Trapezoidal method using RK equation while checking for error and halving step size if greater than the error, but I don't know how.
Message was edited by: Adam Ferrick
Solved! Go to Solution.
This just in: I got the Simpson's part, too. Check my modified .xmcd file to see!
Friend helped me out a bit, got the answer. See attached
Sorry, an animation for the trapezoidal rule wouldn't have helped. I needed to create a function to do that.
Adam Ferrick wrote:
Sorry, an animation for the trapezoidal rule wouldn't have helped. I needed to create a function to do that.
If you check my .xmcd file that I flagged as the correct answer you can see my 2nd function doubles n for me if the error is not met, instead of your program which requires a manual input of n.
Out of curiosity, why are you doing it this way? Why not just use the integral function?
For a homework assignment my professor wanted us to see the "Why" behind different methods of integration. For part B I have to do the same thing with Simpson's 1/3 Rule. I also have to compare the answer to the actual integral function.
I see. Something that may be of interest: "Help", "E-books", "Data Analysis Extension Pack", "Application Examples", "Numerical Integration of Data".
Interesting indeed. I think that would have helped with simply computing the Trapezoidal method, but not with the part about doubling the number of steps if an error tolerance is not met. Good find!
Adam Ferrick wrote:
For a homework assignment my professor wanted us to see ....
Tell please to the professor:
There is a method of rectangles.
Everything else - the distortion (in the age of computers).
I remember in the good old pre-computer time, I cut a piece of graph paper on the paper under the courve, weigh it on the chemical balance (with little weights), and determines the integral ....!
ValeryOchkov wrote:
Adam Ferrick wrote:
For a homework assignment my professor wanted us to see ....
There is a method of rectangles.
See please the animation Video Link : 1474
This just in: I got the Simpson's part, too. Check my modified .xmcd file to see!
That's good
But if you want to compare the trapezoidal rule to Simpson's rule, how many iterations did each take to get the error below 10^-4?
The goal was not comparing simpson's and trapezoidal, it was computing the "integral" with a certain step size and comparing that to a previous value to calculate the error between iterations. The trapezoidal program went through 6 iterations before it converged, and Simpson's went through 4 iterations before it converged.