Integration using Trapezoidal Rule and Redlich-Kwong
- November 18, 2015
- 4 replies
- 9745 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

