Skip to main content
1-Visitor
November 18, 2015
Solved

Integration using Trapezoidal Rule and Redlich-Kwong

  • November 18, 2015
  • 4 replies
  • 9731 views

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

Best answer by aferrick

This just in: I got the Simpson's part, too. Check my modified .xmcd file to see!

4 replies

aferrick1-VisitorAuthor
1-Visitor
November 19, 2015

Friend helped me out a bit, got the answer. See attached

24-Ruby IV
November 19, 2015

One animation

Video Link : 1475

aferrick1-VisitorAuthor
1-Visitor
November 19, 2015

Sorry, an animation for the trapezoidal rule wouldn't have helped. I needed to create a function to do that.

24-Ruby IV
November 19, 2015

Adam Ferrick wrote:

Sorry, an animation for the trapezoidal rule wouldn't have helped. I needed to create a function to do that.

Trapezium_Int.gif

19-Tanzanite
November 19, 2015

Out of curiosity, why are you doing it this way? Why not just use the integral function?

aferrick1-VisitorAuthor
1-Visitor
November 19, 2015

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.

19-Tanzanite
November 19, 2015

I see. Something that may be of interest: "Help", "E-books", "Data Analysis Extension Pack", "Application Examples", "Numerical Integration of Data".

aferrick1-VisitorAuthorAnswer
1-Visitor
November 20, 2015

This just in: I got the Simpson's part, too. Check my modified .xmcd file to see!

19-Tanzanite
November 20, 2015

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?

aferrick1-VisitorAuthor
1-Visitor
November 20, 2015

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.