cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

Making a piecewise function using a program structure

MarkBuckton
10-Marble

Making a piecewise function using a program structure

I am trying to join two flow regimes (weir flow and orifice flow) into one continuous vector / function. For some reason its giving me an error and I not sure why. You will see that I designed a similar structure (see first program block) which also contains if statements i.e.comparing each array element in turn at least I think that is what it is doing? I believe all the units are correct for taking into the second programming block, so why dosn't the program structure return a array of values. Also is there a way to avoid having to vectorizing the result from a program block output i.e. placing the forward arrow above the result. I must admit I am not sure why I have to from a mathematical perspective but it seems to work. My main concern however is programming block 2.

Thanking you in advance.

Regards, Mark

ACCEPTED SOLUTION

Accepted Solutions

Another point to note is that the definitions for Q.o & Q.w have index variable as a parameter while the Q.out function calls them with parameter h

Capture.PNG

Attached will run, but (as the D.orifice issue is not correctly resolved) he plot has a discontinuity.

Regards

Andy

View solution in original post

5 REPLIES 5

Check units please

h.png

Another point to note is that the definitions for Q.o & Q.w have index variable as a parameter while the Q.out function calls them with parameter h

Capture.PNG

Attached will run, but (as the D.orifice issue is not correctly resolved) he plot has a discontinuity.

Regards

Andy

Werner_E
25-Diamond I
(To:MarkBuckton)

You really should be more careful with units and variable/function names!!

  1. The last definition of h is that h is a function, so you cannot call Q.out(h) as Q.out() is not written to take a function a argument. You tend to use the same name for different structures - thats calling for troubles.
  2. calling Q.out(1 m) should work as it seems you intend to feed you function Q.out with an argument of dimension length. So h<=h0 works because h0 also is a length (0m), but what about h/D.orifice + h? D.orifice has dimension length so the quotient is unitless and naturally cannot be added to a length (h).
  3. Q.w() is written as a function with a dimensionless integer(!!!) argument but you feed it with h-h0 which obviously are supposed to be of dimension length - again, that cannot work! The very same applies to function Q0.

Thanks everyone I agree there are a lot of sloppiness here but I am so glad Prime wont accept sloppy unit definitions which is a good thing. Looks like one should avoid using range variables as function variables. Looking back I don't know why I did this I.e not a smart way to go. Many thanks to Mr. Westerman, as for the discontinuity I will have to resolve this I must retread the paper where I obtained these formulas. It is still not obvious why one has to vectorize results in some cases I hope the penny drops as to why and when to use this modifier.

Werner_E
25-Diamond I
(To:MarkBuckton)

It is still not obvious why one has to vectorize results in some cases I hope the penny drops as to why and when to use this modifier.

Maybe the pic with examples below helps.

If you are sure that your formulas don't conatain any operations defines differently for vector than for scalars (dot product) you may omit vectorization but if you don't want to check every formula you are on the safe side to use vectorization. You may use the vetorize operater when calling a function, but you may also vetcorize the function definition itself and can save the vectorization when calling.

As an alternative you can use a range variable to create the result vector w/o vetcorization or use a small program with a for-loop.

vectorize.png

Announcements

Top Tags