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

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Symbolic calculation, units and programs in MP3.0

ptc-6851167
1-Newbie

Symbolic calculation, units and programs in MP3.0

Hello to everyone,

I'm just giving a try to the MP3.0 trial version.

Basically, somewhere in the worksheet I need to find the max. value of a function over the range of its parameters.

Unfortunately I have some problems with the programming tools.

I'm struggling for a while to implement correctly the program I want as I'm not familiar with this programming feature of MathCAD, but I think there is a problem with units and/or external functions to the program.

I made a file with an example.

What do you think ?

9 REPLIES 9
athurin
4-Participant
(To:ptc-6851167)

When using ranges, if you use units, all elements must have units. If you use units, you must indicate the step size

test_prog_unit.png

for 0g to 10g by steps of 1g (but you can make it smaller if you want).

By the way, if you don't use units and don't specify step size, the default step size will be used (and it is 1).

Adrien Thurin wrote:

By the way, if you don't use units and don't specify step size, the default step size will be used (and it is 1).

... or -1.

minone.png

1) What do you think that "unit" g should be? In Mathcad g is the constant of gravity (unless you redefine it), no matter if you label it as constant or as unit. If you want grams you should write gm.

2) When defining range variables with units, you have to provide the second value and to add units allover.
like: 0gm,1gm..10gm

1.png

Your second exampled worked because when you set up x e 0 .. [anything] you define a unitless scalar range with step 1. In my opinion the endvalue should throw an error as in your case its 10 g = 98.067 m/s^2 but it doesn't. Instead the loops goes up to 98 and the result you get is f(98,5).

athurin
4-Participant
(To:Werner_E)

Woops ! I assumed the unit for grams was g and didn't check... shame on me !

Adrien Thurin wrote:

Woops ! I assumed the unit for grams was g

So did J G, I guess.

No, I know it is 9.81 m/s² (as you can see at the end of the second example).

By the way, thank you for the help.

I didn't think about that it would need step+unit... And yet I indicated the step size with the unit in the actual worksheet because I needed a particular step size.

OK, not very bright on my part!

(The unit is not necessary for the first value in this case as it is 0 (logical...), at least it is working without it in this example.)

So it works in the example but not in my program...

(simplified extract : Test.png)

I have to check this out...

J G wrote:

No, I know it is 9.81 m/s² (as you can see at the end of the second example).

Sorry, just thought you mixed up the constant g with unit grams because it was labelled as unit in your sheet and not as constant.

(The unit is not necessary for the first value in this case as it is 0 (logical...), at least it is working without it in this example.)

Careful! In Prime its often necessary to state the unit even if the value is zero - this is because of the change from static to dynamic unit checking. So its a good idea to always add the unit.

So it works in the example but not in my program...

(simplified extract : Test.png)

I have to check this out...

Hard to say whats the matter without having the full sheet. It looks like the function F.P_EL_axial is unknown for numerical evaluation. You have evaluated the function symbolically. Does it evaluate numerically as well? If no, the problem is not the loop but the way the function is defined.

OK, thanks for your time, you made me learn two things : correct handling of units in programs and this labelling feature I didn't notice.

(By the way I didn't find "advanced" text and math formating, at least not as "advanced" as it was with previous versions of MathCAD : frame formulae, subscript text, etc.)

The fact is that I'm cheating a little with the software : I solve a dynamic problem explicitly, to get the dynamic torsor as function of numerous parameters (positions, (speeds) and accelerations) but not time because I can only assume max. values of these parameters and not describe them as a function of time (or it would be a hard work, far out of the scope of this problem).

So first, I write all the parameters as a function of time but without defining them. Then MP3.0 do all the job of deriving and solving the functions and equations to get the dynamic torsor as a function of these parameters themselves functions of time. The software warns that there is undefined variables but is doing the job well.

Then I substitute these parameters functions of time by simple variables to get a dynamic torsor function of these parameters.

And finally, I search for the max. values all over the combinations of parameters values.

It works well for the simple examples in the file enclosed, but not in the actual program. I'm still searching for the the mistakes I've made (I know I've done quite a rush job).

Werner Exinger wrote:

1) What do you think that "unit" g should be? In Mathcad g is the constant of gravity (unless you redefine it), no matter if you label it as constant or as unit.

I know two letter g and c - a constant and an unit (acceleration and validity).

Do you know more?

Top Tags