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 the Community Ranking System, a fun gamification element of the PTC Community. X

Translate the entire conversation x

Vector depending on variables

JH_13773851
3-Newcomer

Vector depending on variables

Hello,

 

i like to calculate  force FA depending on three variables hS, hA, Hz.

 

Mathcad calculates FA and put into a vector.

 

Finally, i like to have the maximum of this vector.

 

Typing max(FA) gives back the whole vector not the single maximum value.

 

Also for mean and other functions.

 

Thank you for your help.

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:JH_13773851)

If you define a vector with 8 steps you will get a vector with 9 entries.

So the number of combinations from vectors with 8 steps, 6 steps and 12 steps would be 819, not 576 😉

 

I would suggest a different approach. Instead of creating these huge input vectors with repeated values I would leave them as we already had defined. 

Its a good thing that you have turned all your calculations into function of the three inputs.

I think what you are interested in are the three forces and the maximum of each.

So why not separate definition and display of values.

Define your functions first without having  the inputs already defined and without displaying numeric intermediate results like angles.

After all functions are defined, define the three input vectors and use a program to cycle through all values:

Werner_E_0-1752251229164.png

Werner_E_1-1752251266541.png

FAall, etc. are vectors with 819 elements (because I used your example of 8, 6 and 12 steps for the input vectors).

At the end of the attached Prime 10 sheet I also show a way to create a table of values, not sure if that would be of interest:

Werner_E_3-1752251829927.png

As a byproduct, you also are offered a way of creating the three input vectors with repeating elements that you have suggested. You can therefore continue with your approach and then decide which is more suitable for you.

 

Prime 10 sheet attached

 

 

View solution in original post

7 REPLIES 7
Werner_E
25-Diamond I
(To:JH_13773851)

Welcome to the forum.

You should always whenever somehow possible attach your worksheet and also say which version of Prime you are using. This is especially important to do if, like so many, you are not using the latest version.

 

According your problem - you are not showing how you defined your  three variables.

My guess is that you defined them as ranges and not as vectors which would explain the effects you experience.

 

Solution is to define the three input variables as vectors and use vectorization when you call your function FA(hS, hA, hZ). Depending on the way your function FA is defined it could be that explicit vectorization is not necessary because Prime uses automatic implicit vectorization, but I would strongly suggest that you apply explicit vectorization in any case.

 

If you are using Prime 11 you can use the convenient new function "vec" to create the vector. If you are using an older version there sure are many other ways to create your vectors or turn the ranges you have defined into vectors.

 

If you are unsure, feel free to come back here, attach your worksheet, state the version and ask.

 

BTW, the difference between vectors and ranges has confused users ever since Mathcad was originated. With Prime it got even worse, because both look completely identical when displayed. So you are certainly not alone and without doubt not the first to have problems with this. 😉

 

Here is a small example demonstrating the difference between ranges and vectors and also the usage of vectorization:

Werner_E_1-1752135611079.png

 

Prime 11 sheet attached

Thank you Werner for your fast response. I am using Prime 10.0.1.0. I also attached my mcdx. 

 

You are right, i am using ranges for defining hS, hA, hZ.

 

My sheet calculates force on three cylinders of an arm with three joints.

 

The strokes of the cylinders hS, hA, hZ affect the resulting force.

 

The idea is to calculate various positoins (i) of hZ, various positoins (i) of hA and various positoins (i) of hS to have in total i^3 positions with respective force.

 

When I am using the range function e.q.

hA:=0,885..885 (two positions)

hS:=0,885..885 (two positions)

hZ:=0,885..885 (two positions)

It calculates 2^3=8  positions.

 

But when i am using:

hA:=[0 

        885] (two positions)

hS:=[0 

        885] (two positions)

hS:=[0 

        885] (two positions)

 

Result is also a vector 2 positions.

 

So I think now I am searching for soultion to automize definition of my input vectors, because I like to vary the cylinder position of each cylinder at least by 10 steps. If I am right i need three vectors each with 10^3 entries.

 

thanks in advance

 

 

 

Werner_E
25-Diamond I
(To:JH_13773851)

Here are two ways to create the necessary input vectors.

For convenience I use a variable "n" which is the number of intervals between start and end value of the vector which means that the vectors will have n+1 elements each.

First method uses a range variable "i" which had to be defined:

Werner_E_0-1752161766604.png

A range variable is not a collection of values but rather kind of an implicit loop. So the same effect can be achieved by using a small utility program with an explicit for-loop. This utility function could be hidden at the top of the sheet in a collapsed area or to the right of the right margin. By using this function, we can omit the definition of the range variable “i” which is the reason I prefer this way.

The utility function:

Werner_E_1-1752162001351.png

and how to use it:

Werner_E_2-1752162052002.png

 

A word of caution: You called your various function with the vectors h.Z, etc as function arguments and did not use vectorization (the arrow over the expression).  This seems to work well in the case of your function, but can lead to dangerous errors that are difficult to detect.

For example, if one of your functions contained an expression such as

Werner_E_3-1752162447969.png

the function result would be incorrect when called without vectorization and you might not recognize it at first glance. Here are the differences:

Werner_E_5-1752162488324.png

Reason for the difference is that without vectorization the expression

Werner_E_6-1752162548795.png

is calculated as the scalar product of two vectors. Adding the vector h.S makes the result a vector again.

Using vectorization lets Prime do the multiplication element by element and collects the results in a vector, which is whats needed here

Werner_E_7-1752162671034.png

If you feel the using vectorization every time a function is called with vector arguments is annoying and may irritate a reader, you can also apply the vectorization when you define the function. For example:

Werner_E_8-1752162781880.png

So here vectorization is not necessary when you call the function.

Personally I try to use vectorization every time I intend to call a function written for scalar arguments with vector arguments, no matter if its really necessary (because otherwise a scalar product would be calculated) or not - just to be on the safe side.

 

Prime 10 sheet attached

Thank you Werner for you explenations. I think we are getting closer to the solution.

 

I try to rebuild your makeVec function hence i can not open your Mathcad Sheet (my version is 10.0.1.0).

 

I don't know how to use ORIGIN correctly.

 

Everytime I try to ORIGIN+1 it makes this:

JH_13773851_0-1752212120144.png

So i try something like that:

JH_13773851_2-1752212247396.png

thanks in advance

I have to end the for loop with Ri otherwise I get an errror with it. Therefore, i get last value of Ri only.

 

JH_13773851_1-1752212173470.png

 

 

 

 

Werner_E
25-Diamond I
(To:JH_13773851)

I try to rebuild your makeVec function hence i can not open your Mathcad Sheet (my version is 10.0.1.0).

As I also had written, the sheet I had attached in my second reply was created in Prime 10 (actually the exact version 10.0.1.0 which you are using, too). You sure should have no troubles opening it if you are using 10.0.1.0.
I just tried and the sheet I had attached opens without troubles in Prime 10 (no matter if 10.0.0.0 or 10.0.1.0).

 


Everytime I try to ORIGIN+1 it makes this:

Reason for your problem seems to be that you are using the literal index (which is just part of the variable's name and won't allow a "+" and not the vector/matrix index. Furthermore its not "ORIGIN+1" but rather "ORIGIN+i"

 

As you are using the default value 0 for ORIGIN in your sheet it will also work if you are just using the index "i", but it has to be the vector index which you get by typing a "[" (and not Ctrl+-) or you may chose it from the menu.

Werner_E_0-1752230578963.png

BTW, when I used "R" for the local variable I was thinking on "R"eturn value or "R"result. You may chose any name you like 😉

Thank you Werner,

 

you are right it is the correct version of the file you sent. I can open it.

 

Programming of making  one vector works but what i really like to have following.

 

Inputs for start, end and number of steps for each cylinder.

 

Programm has to create three vectors with number of entries iA*iZ*iS like the following pattern:

JH_13773851_0-1752237686846.png

Means result

of first line cyl A retracted, cyl Z retracted, cyl hS retrected

second lin cyl A retracted, cyl Z retracted, cyl hS extended

...

Finally  I like to define something like 8 steps for A, 6 Steps for Z and 12 Steps for S. Means vector with 576 entries.

I hope you can support me with working loops because I stuck in that issue.

 

Werner_E
25-Diamond I
(To:JH_13773851)

If you define a vector with 8 steps you will get a vector with 9 entries.

So the number of combinations from vectors with 8 steps, 6 steps and 12 steps would be 819, not 576 😉

 

I would suggest a different approach. Instead of creating these huge input vectors with repeated values I would leave them as we already had defined. 

Its a good thing that you have turned all your calculations into function of the three inputs.

I think what you are interested in are the three forces and the maximum of each.

So why not separate definition and display of values.

Define your functions first without having  the inputs already defined and without displaying numeric intermediate results like angles.

After all functions are defined, define the three input vectors and use a program to cycle through all values:

Werner_E_0-1752251229164.png

Werner_E_1-1752251266541.png

FAall, etc. are vectors with 819 elements (because I used your example of 8, 6 and 12 steps for the input vectors).

At the end of the attached Prime 10 sheet I also show a way to create a table of values, not sure if that would be of interest:

Werner_E_3-1752251829927.png

As a byproduct, you also are offered a way of creating the three input vectors with repeating elements that you have suggested. You can therefore continue with your approach and then decide which is more suitable for you.

 

Prime 10 sheet attached

 

 

Announcements

Top Tags