Skip to main content
1-Visitor
March 15, 2022
Solved

Finding the index value in a vector for a given value

  • March 15, 2022
  • 3 replies
  • 9625 views

Good Morning, 


I am trying to determine the exact x-location where the maximum deflection occurs. So far I have got a match function: 

 

Callum1995_0-1647345979286.png

I wish to return the index k for which the displacement is maximum, the deflections have been calculated and stored in the vector delta-k. With the index found I can then determine the corresponding location where it is a maximum. 

 

I know there are various topics available on this however I have not been able to get it working so far. 

 

Thanks,

Callum 

Best answer by KevinFinity

Callum,

 

In the Calculation tab, in the Worksheet Settings pane, change TOL to 10^-7

 

Or multiply your max value and entire delta vector by 10^4

KevinFinity_6-1647369873807.png

 

The calculation was working with only one decimal place. When the default unit is meters, 1 mm is within the tolerance of 10^-3 (default setting), and it apparently ignores all of those significant figures. 

 

You will also have to use the 0th index of the match to use it later on when referring to it in vector delta.

KevinFinity_7-1647370078908.png

 

This solves the problem!

3 replies

23-Emerald I
March 15, 2022

If you look at d, there are multiple locations with the max value:

the match function (read the help) returns a vector of the indices that match the requirement within TOL.  If you take a subscript of the match function you will get a single numerical answer, but it may not be the best answer:

Fred_Kohlhepp_1-1647349397244.png

note the change in TOL:

Fred_Kohlhepp_2-1647349444458.png

Sorting thru a vector may not be the best way to find a max value or its location.  Since you already have a function defined, why not find where it's slope is zero?  (Red circles are Express not recognizing previous answers on recalculation.)

Fred_Kohlhepp_3-1647349832094.png

 

 

 

 

1-Visitor
March 15, 2022

Hi Fred, 

 

If you were looking for the maximum deflection at location x=? how would you go about solving. I am unsure on what the best approach would be so if there is an alternative to sorting through a vector that would be brilliant. 

 

Thanks,

Callum 

23-Emerald I
March 15, 2022

See the attached file.  The first derivative of a function is the slope.  When the slope is zero you're either at a maximum or a minimum.

25-Diamond I
March 15, 2022

I have no Prime 7 installed so I cannot open you file and am only using the pic you posted.

The match function always returns a vector of values and even if the result is just one index it will be a 1x1 matrix.

To get the index k you will have to write kmax:=match(.....)[0 to reference the first (and maybe only) element in the resulting vector. I am assuming that you use ORIGIN=0, otherwise you would have to change the index 0 to whatever you had chosen for ORIGIN.

The x value you are looking for should then be xmax:=xdelta[kmax

Remark "[" is the keyboard shortcut for the vector/matrix index

 

Another way to directly calculate the x-value could be using the lookup function -> xmax:=lookup(delta.max, delta, xdelta)

 

BTW, you may have your reasons doing so, but I think it would be easier to deal with the functions you seem to already have directly and don't bother working with vectors of values at all. In case of the max you would have Prime to find the zero(s) of the first derivative of the function delta.total.

 

1-Visitor
March 15, 2022

Thankyou for the reply, 

 

Suppose I have the following extract can you think of anyway to solve for when the function would be a maximum:

Callum1995_0-1647350190240.png

I wish to obtain a result that is of the form maximum deflection along the beam occurs as location x=?. 

 

Thanks,

Callum

 

1-Visitor
March 18, 2022

Thanks Kevin, 

 

This seems to be working now. 

 

Best Regards,

Callum 

12-Amethyst
March 15, 2022

Several ways to find the x value where f(x) is maximum:

1. When using a solve block

Sometimes I use a solve block to go from my moment equation to my deflection equation, and then it's a function rather than a vector of values.

KevinFinity_0-1647368132662.png

Then you can use the root function to find the maxima

KevinFinity_1-1647368429873.png

Root of the derivative works because maxima always occur where the derivative of the function is zero.

Plot them to be sure you got the right one:

KevinFinity_2-1647368548790.png

 

2. built-in solver

Another way of finding maxima is to use the solver. Here is an example:

KevinFinity_3-1647368590467.png

 

3. When using vector

However, you are trying to use a vector of values rather than functions. Here is how I solved the trapezoidal loading on a simply supported beam. Because trapezoidal loading is a piecemeal function, the regular integral doesn't really work. I had to use the definition of an integral to integrate discretely. The programs below use 1000 steps to integrate the moment function into the angle function and then the angle function into the deflection function. 

KevinFinity_4-1647368715722.png

You might find this method useful for your application. 

 

For reference, here is the formula for trapezoidal loading on a beam. This is for a beam that can have different tributary widths on the left and right. It took me a long time to derive this. 

KevinFinity_5-1647369045192.png