Welcome Guest! To enable all features please Login. New Registrations are disabled.

Notification

Icon
Error

Login


Options
Go to last post Go to first unread
Offline .plaid  
#1 Posted : 28 May 2011 20:23:19(UTC)
.plaid

Rank: Newbie

Groups: Registered
Joined: 18/05/2011(UTC)
Posts: 5
Location: Colorado, USA

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
Code:
if Volume[m ≤ 42
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

Edited by user 28 May 2011 20:41:09(UTC)  | Reason: Not specified

Wanna join the discussion?! Login to your SMath Studio Forum forum account. New Registrations are disabled.

Offline TheWizEd  
#2 Posted : 29 May 2011 19:11:19(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
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 Confusion
Ed
Offline .plaid  
#3 Posted : 29 May 2011 20:52:03(UTC)
.plaid

Rank: Newbie

Groups: Registered
Joined: 18/05/2011(UTC)
Posts: 5
Location: Colorado, USA

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<value<50) is m. Very strange.

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
Offline TheWizEd  
#4 Posted : 29 May 2011 21:14:20(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
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.

Edited by user 29 May 2011 22:06:13(UTC)  | Reason: Not specified

Ed
Offline .plaid  
#5 Posted : 30 May 2011 02:44:35(UTC)
.plaid

Rank: Newbie

Groups: Registered
Joined: 18/05/2011(UTC)
Posts: 5
Location: Colorado, USA

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
Offline TheWizEd  
#6 Posted : 30 May 2011 04:26:33(UTC)
TheWizEd


Rank: Advanced Member

Groups: Registered
Joined: 04/07/2010(UTC)
Posts: 178
Man
United States

Was thanked: 19 time(s) in 13 post(s)
plaid,

Some times it take a fresh set of eyes to see the logic.
Ed
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.