Community Tip - Learn all about the Community Ranking System, a fun gamification element of the PTC Community. X
I am working on a sample to develop my calculations.
I used both If .. Then and While.
But, I can get the results: J is not adding up. Looks like J keeps remaining at 1.
I request help.
Solved! Go to Solution.
Your programs don't show what you intend to do if the function argument x is not exactly in the list of nominal diameters.
The programs (with Terry's fix applied) will return just the last value of j in this case (15).
If, as I assume, that's not intended, you could simply place the return value you want to see in case of an invalid x in the last program line, like:
To achieve what you obviously intend to do (take the nominal diameter ND, lookup the corresponding outer diameter OD and use it to calculate the cross-sectional area) could more easily be done using the "lookup" function:
To avoid the error in case x is not in the list you could add your own return value in case lookup fails:
I think that returning the index j as well was done just for debugging. But in case you really need that index you could use the "match" function (see attached sheet).
You may also just use the next larger value in ND in case x is not found in that list
Similarly you could also decide to use the next smaller value or the nearest value (see attached sheet).
And of course a further option would be to use linear interpolation to deal with x-values not in the ND-list.
Prime 11 file attached
Hi,
The comparison equals is a bold equals sign and is entered by the following keys together [CTRL][equal sign].
Cheers
Terry
Your programs don't show what you intend to do if the function argument x is not exactly in the list of nominal diameters.
The programs (with Terry's fix applied) will return just the last value of j in this case (15).
If, as I assume, that's not intended, you could simply place the return value you want to see in case of an invalid x in the last program line, like:
To achieve what you obviously intend to do (take the nominal diameter ND, lookup the corresponding outer diameter OD and use it to calculate the cross-sectional area) could more easily be done using the "lookup" function:
To avoid the error in case x is not in the list you could add your own return value in case lookup fails:
I think that returning the index j as well was done just for debugging. But in case you really need that index you could use the "match" function (see attached sheet).
You may also just use the next larger value in ND in case x is not found in that list
Similarly you could also decide to use the next smaller value or the nearest value (see attached sheet).
And of course a further option would be to use linear interpolation to deal with x-values not in the ND-list.
Prime 11 file attached
Thanks for the great help. Help to improve Mathcad programming.
I rarely use MathCAD. But, I will try to use often.
Thank you for the great reply.
I explored all the options.
I did well. BUt I get some issues.
When my input is not a listed data, I don't get the message.
I appreciate if you can shed some light on this issue.
Please see the attched Mathcad file.
Thanks again
See file.
With a unit applied to the expressions that return the message get the question mark. Just delete the units on the end of the expression.
Thanks a lot Terry.
I got the idea. I can, for now, continue with my previous calculation procedure.
All the best.
Your previous reply was excellent.
As I got the preliminary understanding, I moved to solve tmy problem in hand.
I do not like to bug you. But, at this moment, I need help for a one more time.
I still have the problem of not incrementing.
I request you help.
Mathcad (11.0.0.0) file is attached here to.
THANK YOU
Re: 008-MCAD005 PTC2
The for loop only operates once as the if statement is true first time through. Then it returns the 1 and QSp1.
Perhaps if you describe in words what you are trying to achieve rather than programming we may be able to help better.
Cheers
Terry
Are you aware that a 'return' statement stops the execution of a program?
So your program stops as soon as 'Detector' gets equal or larger than QSP.1. This is already the case right the first time and so your program already stops at i=0.
BTW, it's not good programming style to alter the loop variable i of a for-loop. You should avoid the i <- i+1 assignment.
Here you see in variable YY all the results from i=1 up to i=6. Detector is larger in all cases:
It may not have to do with the problem you encounter but I think you made a mistake when you defined function Pvh.
Your argument rho could be omitted as its not used in the function definition. Maybe rhow was meant to be just rho?
This single problem gave me a lot of skills - of course because of you.
I appreciate your good karma. What can I give you in return? I may say ALL GODS BLESS YOU ALL THE TIME FOE EVER!
As Terry already explained is the problem that Prime does not allow to add a unit to a text string.
As an alternative to the text output you may use an 'impossible' return value (such as 0 in or a negative length), or you may return a NaN (not-a-number) with appropriate unit or you may create your own error-message:
Hi Werner_E
Well, you kind of can add units to a text string via the format function.
(Mathcad Express 11, hence the convoluted expressions. Prior workings hidden to avoid hysterical laughter at my misunderstanding of what's going on)
Stuart
@StuartBruff wrote:
Well, you kind of can add units to a text string via the format function.
Hmm, I would say that's rather adding units IN a string, not TO a string.
I wonder if it would be possible to write a function "unit2str" ?
Of course I would strive for a method that does not consist of treating all possible units individually, like
@Werner_E wrote:
@StuartBruff wrote:
Well, you kind of can add units to a text string via the format function.
Hmm, I would say that's rather adding units IN a string, not TO a string.
I wonder if it would be possible to write a function "unit2str" ?
Of course I would strive for a method that does not consist of treating all possible units individually, like
WE: "I wonder if it would be possible to write a function "unit2str" ?"
No. Not at all. Impossible, I tell you, absolut unmöglich!!
Stuart
(Mathcad Express 11 displays numbers less than 10-15 as 0. Changing the zero threshold is a Premium feature)
Oh, all right, just because you didn't ask, and I've finished my coffee and had a play with another worksheet ....
unit2str Mathcad Express 11 worksheet attached. Tidied up a bit, but not complete in terms of derived units.
Stuart
Wow, impressive! Seems you had more than just one cup of coffee.
Definitely something to steal and keep 😉
Thank you, but, no, just the one cup. It required less tidying up than I thought,
Although I did accidentally delete some work I'd done on the reverse transformation str2unit.
I'm half sure I did something similar a long time ago, but I couldn't find the worksheet, so I thought it was quicker to recreate it from scratch. I've added a few more derived units to the worksheet and created a very inelegant str2unit.
I might brood on str2unit for a little bit longer, as there is at least one bug in it that I need to fix, and a few more derived units to add. Or, apart from the bug fix, I might not, as I have a shedload of other worksheets that I'm working on Expressifying.
You might notice one significant omission from the vector of frequencies, and therein lies my bug.
Stuart
You might notice one significant omission from the vector of frequencies, and therein lies my bug.
Hertz without any prefix?
@Werner_E wrote:
You might notice one significant omission from the vector of frequencies, and therein lies my bug.
Hertz without any prefix?
Yes, and that's generic across all units. After the meeting I'm in has finished, I might get a bit of time to restructure the algorithm.
Stuart
After dealing with a number of non-Mathcad related tasks, I got around to sorting out the problem. I now have a lot of tidying up to do, but won't be able to get around to for at least a couple of days due to other stuff getting in the way.
OOIC, does anybody know of a way to break out of a fold?
Stuart
I got to work on my calculations comfortably. I thank everyone for the help.
Attached here to is one of my final calculation, but WIP: I need to add some images from a Revit model.
