Skip to main content
1-Visitor
July 6, 2010
Question

Vector function

  • July 6, 2010
  • 2 replies
  • 13100 views

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

2 replies

19-Tanzanite
July 6, 2010

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?

1-Visitor
July 6, 2010

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.

19-Tanzanite
July 6, 2010

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.

1-Visitor
July 7, 2010

"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

1-Visitor
July 7, 2010

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

1-Visitor
July 9, 2010

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.