1 Pages (6 items)
Iteration: Unexpected Results - Messages
#1 Posted: 5/28/2011 1:23:19 PM
Hello! This is a great MathCAD clone that I hope to share with my students in the fall. Right now, however, I am having trouble with an iteration process; I hope you can show me where I'm mucking it up.

You may recognize this as an overly-simple feedback control process, and you'd be right. Within a specified range a valve is open at a percentage between 0% at 50 & 100% at 40 - between 40 & 50 the valve is open based on the difference between the current volume (e.g. water in a tank) and some pre-determined "set value," in this case 44.
The process iterates using the variable m, but it seems like something strange happens at the 41st iteration. You can see what I mean by simply typing "Valve.Per=" because the volume is less than the "floor" value of 40 the Valve.Per value should stay at 100. It seems, though, that after the 40th iteration things get wonky. Actually, the problem occurs on the next iteration following whatever value is set for the "floor" - by this I mean if I change the first if check to say then the problem arises on the 43rd iteration. It seems as if the value of m is being passed around incorrectly, but I can't see what I've done to cause this.
Any help or insight would be greatly appreciated, and thank you for your time.
All the best,
.plaid

You may recognize this as an overly-simple feedback control process, and you'd be right. Within a specified range a valve is open at a percentage between 0% at 50 & 100% at 40 - between 40 & 50 the valve is open based on the difference between the current volume (e.g. water in a tank) and some pre-determined "set value," in this case 44.
The process iterates using the variable m, but it seems like something strange happens at the 41st iteration. You can see what I mean by simply typing "Valve.Per=" because the volume is less than the "floor" value of 40 the Valve.Per value should stay at 100. It seems, though, that after the 40th iteration things get wonky. Actually, the problem occurs on the next iteration following whatever value is set for the "floor" - by this I mean if I change the first if check to say
if Volume[m ≤ 42
Any help or insight would be greatly appreciated, and thank you for your time.
All the best,
.plaid
#2 Posted: 5/29/2011 12:11:19 PM
plaid,
Your going to have to be more specific about whats wrong.
If Volume[m is less than or equal to 42 Valve.per[m = 100 except for m=1 its 1
If Volume[m is greater than 50 Valve.per[m = 0
Between 42 and 51 Valve.per[m = 3*diff[m where diff[m is 43 to 50
Seem right
Your going to have to be more specific about whats wrong.
If Volume[m is less than or equal to 42 Valve.per[m = 100 except for m=1 its 1
If Volume[m is greater than 50 Valve.per[m = 0
Between 42 and 51 Valve.per[m = 3*diff[m where diff[m is 43 to 50
Seem right

Ed
#3 Posted: 5/29/2011 1:52:03 PM
Hi Ed,
Thank you for the opportunity to clarify my problem. First, allow me to say that the process, as written above, shows an error at the 43rd iteration (m=43); when the "valve open 100%" check (i.e. the first if condition) is set to 40 the problem arises when m=41. So we see that the problem appears at the "floor+1" iteration. Now, to the problem itself....
After the process is calculated, I can look at the Valve.Per vector to see at what percentages the valve was open. Up until the "floor"th iteration the valve is open 100% but then on next pass Valve.Per returns 129 (for floor=42), which suggests that the 3rd if check was true. The only way this can be is if the Volume is greater than or equal to 42 and less than 50. However, reveiwing the Volume vector shows that this is not the case: at the 43rd iteration Volume=17.945. The only value that meets the conditions (i.e. 42
Further, since the Valve.Per[43 value is 129, that means that diff[43=43, which would mean that Volume[42=1.
As an aside I changed the code slightly so that diff[(m+1):44-Volume[m and the results aren't much better, but it makes me think that I'm not indexing something else correctly.
Also, I apologize for not including correctly-formatted code, I'm on my phone at the moment.
Any thoughts would be most appreciated,
.plaid
Thank you for the opportunity to clarify my problem. First, allow me to say that the process, as written above, shows an error at the 43rd iteration (m=43); when the "valve open 100%" check (i.e. the first if condition) is set to 40 the problem arises when m=41. So we see that the problem appears at the "floor+1" iteration. Now, to the problem itself....
After the process is calculated, I can look at the Valve.Per vector to see at what percentages the valve was open. Up until the "floor"th iteration the valve is open 100% but then on next pass Valve.Per returns 129 (for floor=42), which suggests that the 3rd if check was true. The only way this can be is if the Volume is greater than or equal to 42 and less than 50. However, reveiwing the Volume vector shows that this is not the case: at the 43rd iteration Volume=17.945. The only value that meets the conditions (i.e. 42
Further, since the Valve.Per[43 value is 129, that means that diff[43=43, which would mean that Volume[42=1.
As an aside I changed the code slightly so that diff[(m+1):44-Volume[m and the results aren't much better, but it makes me think that I'm not indexing something else correctly.
Also, I apologize for not including correctly-formatted code, I'm on my phone at the moment.
Any thoughts would be most appreciated,
.plaid
#4 Posted: 5/29/2011 2:14:20 PM
plaid,
Volume[m is checked before Volume[m is adjusted for flow.
Did you want Volume[m+1 to be adjusted for the next iteration?
Also I noticed if Valve.per ranges from 0% to 100% then the flow ranges from (0.5-0.1) to (0-0.1) after 100 iterations the cumulative flow is maximum 40+1. It won't reach 42 in the 100 iterations.
Volume[m is checked before Volume[m is adjusted for flow.
Did you want Volume[m+1 to be adjusted for the next iteration?
Also I noticed if Valve.per ranges from 0% to 100% then the flow ranges from (0.5-0.1) to (0-0.1) after 100 iterations the cumulative flow is maximum 40+1. It won't reach 42 in the 100 iterations.
Ed
#5 Posted: 5/29/2011 7:44:35 PM
Hi Ed,
My thinking was that, after the first pass, it didn't matter if the Volume was adjusted before it was checked or after. You're right that my model adjusted the Volume after it was checked, and I think this was part of the problem. By changing the for loop to range(1,100) and the Volume[m calculation to Volume[(m+1) for the next pass it seems to work as expected now. The disappointing thing is that I'm not enough of a programmer to understand why this would make such a difference!
Now I just need to find a way to hard-cap the Valve.Per at 100% and I think I'm set. I think one more if-check should do the trick.
Thank you for your replies, Ed, I appreciate your insight. I'll have to do some reading to figure out why it matters where in the loop an adjustment is made.
All the best,
.plaid
My thinking was that, after the first pass, it didn't matter if the Volume was adjusted before it was checked or after. You're right that my model adjusted the Volume after it was checked, and I think this was part of the problem. By changing the for loop to range(1,100) and the Volume[m calculation to Volume[(m+1) for the next pass it seems to work as expected now. The disappointing thing is that I'm not enough of a programmer to understand why this would make such a difference!
Now I just need to find a way to hard-cap the Valve.Per at 100% and I think I'm set. I think one more if-check should do the trick.
Thank you for your replies, Ed, I appreciate your insight. I'll have to do some reading to figure out why it matters where in the loop an adjustment is made.
All the best,
.plaid
#6 Posted: 5/29/2011 9:26:33 PM
plaid,
Some times it take a fresh set of eyes to see the logic.
Some times it take a fresh set of eyes to see the logic.
Ed
1 Pages (6 items)
-
New Posts
-
No New Posts