Get Help

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community
- :
- PTC Mathcad
- :
- PTC Mathcad
- :
- Re: Vector function

Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-06-2010
05:07 AM

07-06-2010
05:07 AM

Vector function

Hi

I am trying to create a function which creates a vector and incorporates units, please see attached.

The function currently works, but I want H_units to be calculated automatically if possible, with the user having to input the units.

I have been playing with the parse numerical functions sheet which Stuart posted a while back with little success.

Cheers

Mike

Labels:

24 REPLIES 24

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-06-2010
06:55 AM

07-06-2010
06:55 AM

Re: Vector function

Sorry, but I'm not sure I understand what you are trying to do. What do each of the arguments to vec_cw_unit represent? What should the calulation of H_units be based on?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-06-2010
07:42 AM

07-06-2010
07:42 AM

Re: Vector function

Richard

Sorry my explanation us poor.

vec_cw_unit(L,H,H_units_,units) -

L = Low number of the vector (start)

H = High number in the vector (Stop)

H_units = Was added to remove the units from this input, as quite often I would define this above as in the worksheet, but the units have to be removed so the vector can be created.

units = this will define the vector in the chosen unit system.

I might be getting this wrong but I couldn't define the for loop inside the program without removing the units.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-06-2010
08:35 AM

07-06-2010
08:35 AM

Re: Vector function

Here are a few alternative ways of doing it.

Degrees are a bad choice for testing functions with units, because Mathcad does not consider them to be a unit.

You can't convert a string to a unit in MC12 or later, because of SUC. You are not allowed to have any function in which the returned units depend on the value of the arguments. Your str2unit2 function will only work in the trivial case of all the units being the same.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
02:38 AM

07-07-2010
02:38 AM

Re: Vector function

Richard Jackson wrote:

Here are a few alternative ways of doing it.

Degrees are a bad choice for testing functions with units, because Mathcad does not consider them to be a unit.

You can't convert a string to a unit in MC12 or later, because of SUC. You are not allowed to have any function in which the returned units depend on the value of the arguments. Your str2unit2 function will only work in the trivial case of all the units being the same.

Cheers Richard,

Cheers for the examples. It seems my idea is a little pointless when the vector can simply be multiplied by the desired unit.

Regarding being told that MC12+ can't convert a string into a unit, because of SUC has just crushed my idea. Will have to carry on dividing by the individual variable's unit if that is inserted as one of the arguments used to create a vector.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
02:59 AM

07-07-2010
02:59 AM

Re: Vector function

... this community site ends in lost worlds .

All that navigation/zigzaging is above my logic and patience.

Your answer is in "Usage" **Algo in Program**

You just need the "units specialist" to complete.

jmG

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
03:11 AM

07-07-2010
03:11 AM

Re: Vector function

jean Giraud wrote:

... this community site ends in lost worlds .

All that navigation/zigzaging is above my logic and patience.

Your answer is in "Usage"

Algo in ProgramYou just need the "units specialist" to complete.

Jean,

I'm not sure what you getting at. What does Algo in Program mean?

Mike

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
09:18 AM

07-07-2010
09:18 AM

Re: Vector function

MIke Armstrong wrote:

Regarding being told that MC12+ can't convert a string into a unit, because of SUC has just crushed my idea. Will have to carry on dividing by the individual variable's unit if that is inserted as one of the arguments used to create a vector.

Well, I really overstated that limitation. You can convert a string to a unit. You can even create a function that returns different units depending on the input string. What you cannot do is create a function that returns different units that have different dimensions. I see you pulled that function from Stuart's worksheet:

which is in this thread:

http://communities.ptc.com/message/135734#135734

You will notice that the dimensions of the units are never mixed.

There is also the possibility to circumnavigate SUC and assign a variable with units based on a text string using a scripted component. See Stuart's second worksheet in the thread above or the original component from Tom in this thread:

http://communities.ptc.com/message/58289#58289

The big restriction on the use of this technique is that you must modify an existing math region. You can't create a new one. It is also not backward comptible with any version prior to 12.

So whether it is possible to do what you want depends on exactly what you are trying to do. If you can provide a more detailed description of the end goal maybe I can point the way to a solution (or maybe not).

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
10:31 AM

07-07-2010
10:31 AM

Re: Vector function

Richard Jackson wrote:

The big restriction on the use of this technique is that you must modify an existing math region. You can't create a new one. It is also not backward comptible with any version prior to 12.

So whether it is possible to do what you want depends on exactly what you are trying to do. If you can provide a more detailed description of the end goal maybe I can point the way to a solution (or maybe not).

I have had many problems with this in the past.

- As an Engineer many of my calculations have different units, so with M14 not allowing mixed unit arrays each of the variables have to be divided by it's unit in order to create a results table. Usually I pass the results to Excel, but again I have to divide each of the variables by its unit.
- The other problem is when creating a vector and using a pre defined varible as one of the argument which has units, as in my first post the user has to divide that by the corresponding unit or manually put the number in.

Please see attached for an explanation on both.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
03:40 PM

07-07-2010
03:40 PM

Re: Vector function

Well, your first example will not work because you have passed the function a value of N that has units. Then you subtract 1 from it, and you can't add or subtract quantities with different units. But if N is supposed to be a number (and in fact it has to be an integer, because it's the upper limit of a loop variable that is used to index a vector) then why are you putting units on it in the first place?

For your second example, no, there is no automatic workaround. A quantity in Mathcad is stored as a numeric value, expressed in SI units, with a dimension. The original units used to define the variables are not stored. So if I write

A:=1*ft

B:=1*lb

C:=A*B

Then C has the numeric value 0.138 and the dimensions L*M. You can automatically get the unitless value 0.138 by dividing C by UnitsOf(C) (which are given as m*kg), but there is no way to automatically divide by ft*lb to get 1. If you want to do that you must do it explicitly.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
02:48 AM

07-08-2010
02:48 AM

Re: Vector function

Richard Jackson wrote:

Well, your first example will not work because you have passed the function a value of N that has units. Then you subtract 1 from it, and you can't add or subtract quantities with different units. But if N is supposed to be a number (and in fact it has to be an integer, because it's the upper limit of a loop variable that is used to index a vector) then why are you putting units on it in the first place

It was an example of trying to create a vector with the same number of elements as L.pipe, without having to type the numerical value and divide by the units of L.pipe - I knew it wouldn't work I was just trying to explain my method in my madness.

Richard Jackson wrote:

For your second example, no, there is no automatic workaround. A quantity in Mathcad is stored as a numeric value, expressed in SI units, with a dimension. The original units used to define the variables are not stored. So if I write

A:=1*ft

B:=1*lb

C:=A*B

Then C has the numeric value 0.138 and the dimensions L*M. You can automatically get the unitless value 0.138 by dividing C by UnitsOf(C) (which are given as m*kg), but there is no way to automatically divide by ft*lb to get 1. If you want to do that you must do it explicitly.

I understand now, I'm just a little disappointed that there isn't a workaround, or Mathcad won't hold the units.

Just one of those things.

Cheers for the help.

Mike

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
10:36 AM

07-08-2010
10:36 AM

Re: Vector function

MIke Armstrong wrote:

It was an example of trying to create a vector with the same number of elements as L.pipe, without having to type the numerical value and divide by the units of L.pipe - I knew it wouldn't work I was just trying to explain my method in my madness.

But what is the number of elements that corresponds to the length of the pipe? It depends on the units of measurement. If the unit you are interested in using happens to be the base SI unit, in this case m, then you can divide by UnitsOf(Lpipe) and round the result to get an integer. If it's any other unit then you have to tell Mathcad what unit you want. Even if the units used to define the variable were stored it would not always be possible for Mathcad to know what you want. Suppose you define the pipe length in m and the diameter in cm and then calculate the volume. What unit to use if you want the same number of elements as the volume of the pipe?

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
11:20 AM

07-08-2010
11:20 AM

Re: Vector function

Richard Jackson wrote:

But what is the number of elements that corresponds to the length of the pipe? It depends on the units of measurement. If the unit you are interested in using happens to be the base SI unit, in this case m, then you can divide by UnitsOf(Lpipe) and round the result to get an integer. If it's any other unit then you have to tell Mathcad what unit you want. Even if the units used to define the variable were stored it would not always be possible for Mathcad to know what you want. Suppose you define the pipe length in m and the diameter in cm and then calculate the volume. What unit to use if you want the same number of elements as the volume of the pipe?

It seems like this thread is dead. My idea doesn't seem to be applicable or valid. Just bugs me when I get an idea and it can't be done.

Cheers for all the help, much appreciated.

Mike

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
11:31 AM

07-08-2010
11:31 AM

Re: Vector function

Just bugs me when I get an idea and it can't be done.

I don't think you are alone in that respect

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
01:38 AM

07-08-2010
01:38 AM

Re: Vector function

You have too long an explanation of your misery about units. Use the basic unitless engineering formula(s), as given in their original unit system, then append your client unit system. Doing so, i.e: not carrying units in calculations, the entire work is traceable in both versions ... unitless then converted. An augmented data table can't obviously support mixed units per columns, but a nested data table should. Add these little demo to the function I have passed for you "Algo in Program"

jmG

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
03:19 AM

07-08-2010
03:19 AM

Re: Vector function

jean Giraud wrote:

You have too long an explanation of your misery about units. Use the basic unitless engineering formula(s), as given in their original unit system, then append your client unit system. Doing so, i.e: not carrying units in calculations, the entire work is traceable in both versions ... unitless then converted. An augmented data table can't obviously support mixed units per columns, but a nested data table should. Add these little demo to the function I have passed for you "Algo in Program"

jmG

I am trying to get my head round what your worksheet "Algo in Program" is achieving.

The reason for the use of Mathcad is becuase of its ability to handle units. If I wanted to work through calculations unitless I could use a Excel or similiar software.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
01:34 PM

07-08-2010
01:34 PM

Re: Vector function

I am trying to get my head round what your worksheet "Algo in Program" is achieving.

The reason for the use of Mathcad is becuase of its ability to handle units. If I wanted to work through calculations unitless I could use a Excel or similiar software.

I am trying to get my head round what your worksheet "Algo in Program" is achieving.

The reason for the use of Mathcad is becuase of its ability to handle units. If I wanted to work through calculations unitless I could use a Excel or similiar software.

__________________________________

Mathematics are two things essentially:

1. Scalar

2. Unitless

So is Mathcad = scalar and unitless.

On one side you have the engineering formula(s), unitless c/w the corresponding constants in the system of the originator ... that you first convert if required. Then you carry the entire project unitless and the result is in the "Engineering system of unit" . At this point and only at this point the "Mathcad Unit System" may come into play for your client ... for instance : I read "Hg from the transmitter [the closest unspoiled process variable] ... I apply Jo Blo engineering formula , but my client wants it in MPa ... then just plug the Mathcad "Unit definer" and it converts to MPa.

That is too simple ! In real Engineering life you will be faced with more calculations and functions, functions that may support units [Given/Find] , but also functions that are purely in "scalar unitless" [root]. Mathcad carrying units is only valid in short sequences not involving solvers , that does not go far. More and more, clients/subcontracts have to comply to codes [ISO ....] which you carry as given, i.e: unitless then convert to meet local unit systems like the US imperial.

The "Algo in Program" is the generalised "vector function" . It passes the list of functions, that you can treat internally or simply as a new global function generator that is in discrete mode for the argument. The "sacalar argument" in the list of function is not a scalar argument anymore, but a "discrete argument" . The final data table is unitless, and you convert each column in the "UserUnitSystem" .

If you work in pure physics and use only little functions like integrals, derivatives ... or relationist formulas, you can carry unit [though not needed] . But as soon as you work in Engineering, the formulas are not as pure and simply "engineering algoritms" . What comes out from what you put in is already in the appropriate units, by the design of the algorithm. From °C and P of steam you get the kg/m³. Apart the logical and memory functions, a computing machinery performs no more maths than the 4 AOPS [Arithmetic Operations] +,-,*,/ ,,, besides these 4, your box and no matter how big it is , your box is empty. It just has instructions to collect the right asembly of [+,-,*,/] to get exp(1.234567890987654321).

Keep visiting the "Mathcad Usage", it's where the good stuff is [generally].

jmG

...............................

What's going on ?

It does not want to spell check !

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-08-2010
01:48 PM

07-08-2010
01:48 PM

Re: Vector function

Pleaseeeeee. Not again!

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-09-2010
02:49 AM

07-09-2010
02:49 AM

Re: Vector function

Do you mean the UNIT ARGUMENT.......

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-09-2010
02:47 AM

07-09-2010
02:47 AM

Re: Vector function

Good point. I take it your against the use of units throughout worksheets.

Your example seems the only valid option to original problem.

Mike

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-06-2010
03:44 PM

07-06-2010
03:44 PM

Re: Vector function

Your "program" is confusing. You're taking the difference of two variables, yet one variable is divided by some sort of unit, but not the other. This can only be the case if the other variable is unitless, in which case, Mathcad rightly would complain about your program, since you cannot plausibly take the difference between something that's dimensioned and something that's not.

The end goal appears to be to use something that's dimensioned as an index for something, but there may be other ways to deal with that. Perhaps you should describe what the actual calculation is supposed to be.

TTFN

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
12:57 AM

07-07-2010
12:57 AM

Re: Vector function

"I am trying to create a function which creates a vector and incorporates units..."

__________________________________

No function creates a vector, the function that creates vector is the function itself,

in which function itself you plug the discretized argument ... multiply by the unit

of your choice = done .

Those things have circulated and circulate regularly.

jmG

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-07-2010
03:25 AM

07-07-2010
03:25 AM

Re: Vector function

jean Giraud wrote

in which function itself you plug the discretized argument ... multiply by the unit

of your choice = done .

I didn't know that M14 didn't have the ability to independently take units away from a variables and that strings cannot be changed into units.

I have stated above in my reply to Richard that my idea seems unachievable and your suggestion seems more valid.

Mike

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-09-2010
09:37 AM

07-09-2010
09:37 AM

Re: Vector function

Mike,

All in all, I think you are lost. Those with unit problem is like this :

==> GrandPa, it's a 2 x3

<== 2 what ? ...

==> Oh ! "meters"

<== 3 what ?

==> ... "cm"

<== How thick ?

==> very thin

<== Yes, but thin like what ?

........................................

Your work sheet was all red 11, what color in 14 ?

It is a lot lot easier to exclude the unit system in the first place, whereas this procedure will accommodate all situations, rather than selecting the cases that work simple. To make it "layman", the unit system is limted to the "toy box", to be quick and practical. Take the cspline qs , no problem to add cm to the X vector and get the work sheet appear done well . NOT SO ! type S = and see the stupid 1/m² appended by the unit system ... S is essentially dimensionless. Next, try to spool the S to file **"Must be dimensionless"** so how can you spool to file a suite of the project .

In your red work sheet, what was the error message "Units don't match ... must be dimensionless" ? who cares because what is the unit of an index in that little for loop. In the second module "Algo in program", if you can't intoduce the unit system in the indexed loop, you can add it to the data table , fine but check the conversion is OK [I didn't] ... fine so far but can't spool to file. At this very same moment in the community, open the "Optical tweezer", c/w units. Works fine for display ... can't extract the data immediately because not in discrete form ... can't spool to file because of the unit in Z.

Worse is :::

"Now, do a numerical time integration of the force on the particle to get the velocity"

So, what do you get for the velocity ... Z(m) ... velocity is some length/some time.

Next. tabulate the independent variable ... no unit ... How come !

I'm no saying the project is wrong [I have no competence in that] but the resulting applied maths are no further exploitable than display, can't be saved in file . That puts us back to Maths are scalar and unitless, and back on the "Engineer design board" where all formulas are in the appropriate unit system as well as applicable codes. The unit system is usefull for the first time design of some physics, but as soon as proved correct, end of it, redo unitless as an exportable product.

Many collabs love to "band aid" projects with units.

jmG

____________________________

Two renewed problems with this community web:

1. past an unknown size of the compobox, the spell check is OFF.

2. past an unknown size of the compobox, the font formating is OFF.

Highlighted
##

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Notify Moderator

07-09-2010
11:08 AM

07-09-2010
11:08 AM

Re: Vector function