## Python Solve Functions - Help For A Noobie

## Python Solve Functions - Help For A Noobie

(OP)

sparked by the python coding discussion by Celt83, I am diving in and trying to solve instantaneous center of rotation problems with python.

The example problem I am trying to solve is outlined here:

https://engineering.purdue.edu/~jliu/courses/CE591...

The way I see this problem, there are (3) unknowns:

I also have (3) equations that need to equal 0

Even in my "native coding language" matlab, this would be somewhat challenging to code, so I am sure it will be fun using this as a learning experience in python.

Anyways, python experts, do you have any suggestions on how to solve this? Should I explore symbolic notation within in python? Should I use a solve block that iterates through the (3) unknowns?

Any help or suggestions/starting points would be appreciated.

My base code that does the guess and check version of this is shown below:

The final print shows the comparison of applied loading verse resist force.

The example problem I am trying to solve is outlined here:

https://engineering.purdue.edu/~jliu/courses/CE591...

The way I see this problem, there are (3) unknowns:

- X location of the instantaneous center of rotation,

- Y location of the instantaneous

- and the Applied Loading that needs to be maxed out.

I also have (3) equations that need to equal 0

- Sum of Forces in the X = 0

- Sum of Forces in the Y = 0

- Sum of Moments = 0

Even in my "native coding language" matlab, this would be somewhat challenging to code, so I am sure it will be fun using this as a learning experience in python.

Anyways, python experts, do you have any suggestions on how to solve this? Should I explore symbolic notation within in python? Should I use a solve block that iterates through the (3) unknowns?

Any help or suggestions/starting points would be appreciated.

My base code that does the guess and check version of this is shown below:

The final print shows the comparison of applied loading verse resist force.

S&T

## RE: Python Solve Functions - Help For A Noobie

similar to this PDF by Bentley for Biaxial base plates: https://communities.bentley.com/products/ram-staad...

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

Examples can be found in my xlScipy3 spreadsheet, which can be downloaded from:

https://newtonexcelbach.com/2018/10/21/iterative-s...

The spreadsheet calls the Python functions from Excel using xlwings, but if you prefer to work directly with Python the Python code is included in the download.

For solvers with more than one unknown see the Solvers2 sheet, which use the Scipy.Optimize minimize function. You need to write a function that returns the difference between calculated and target values for given inputs, with output as a Numpy array, and the minimize function will adjust the inputs to minimize the differences.

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

I am digging into these spreadsheets now and will check in later (got scipy downloaded).

Feel a little overwhelmed currently , lots of learning to ensue...

S&T

## RE: Python Solve Functions - Help For A Noobie

To use Scipy you will also need Numpy, but they are both pretty well indispensable for engineering work with Python.

As an example of what you can do with Numpy, using the xloc list from your code:

## CODE --> Python

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

It is pretty sensitive to where the initial IC coordinates are assumed to be

As IDS notes you can condense a lot of this down to single line steps using numpy arrays, I kept the bulk of it as native python lists and broken up into the calculation steps.

## CODE --> python

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

It is still very sensitive to the initial IC coordinate guess.

There is a great article on AISC for this by G. Donald Brandt from 2nd quarter 1982: https://www.aisc.org/Rapid-Determination-of-Ultima...

## CODE --> python

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

## CODE --> python

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

A few questions for you as I am trying to parse this code.

What does return do in python:

## CODE --> Python

It looks like the program now knows the variables res1, res2, and check_output after the function is performed. Is this correct?

Could the (2) functions you have created be combined into one function? It looks like ic_optomize just builds on results from ic_check? The way I am interrupting this, res_magnitude (the final output from ic_optomize) could be programmed into ic_check.

Could the minimize function then be run ic_check in this case? Or does the function that is being minimized only allowed to have (1) output?

S&T

## RE: Python Solve Functions - Help For A Noobie

Looks like nice method for quick convergence.

S&T

## RE: Python Solve Functions - Help For A Noobie

I have limited knowledge of how to properly use the scipy.optimize.minimize function but it seemed to want one result to check against, i also found that if the result was negative it would keep going negative rather than adjust to start returning back closer to 0.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

red dot is the IC

green dots are the bolts

blue is the load with arrow point in load direction

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

S&T

## RE: Python Solve Functions - Help For A Noobie

## CODE --> Python

It's set up to be called from Excel using xlwings, but you can also call direct from Python:

>>> res = sopt.root(ic_check, x0, vals2)

>>> res.x

array([-1.68496865e+00, 4.01869965e-16, 7.53006559e+01])

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

Inputs are:

x0, the initial guess: [-3, 0,100]

vals2: [[target vals],[[Xloc],[Yloc],[knowns]]]

[target vals] = [0,0,0]

[knowns] = [Eccentricity, Theta, deltamax,Rult]

I didn't have any problem with sensitivity to the initial guess values, and it works very fast with the default solver. Several of the other solvers work very slowly, or not at all.

I will post the Excel version in the next few days. Here's what it looks like:

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

The ic_check function, which is the one you call from sopt.root:

## CODE --> Python

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

I run into some problems with loads at flatter angles and small eccentricities, do you get the same issue. As an example try the load at an eccentricity of 5 and angle of 15 with that same 8 bolt layout.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

the 8 bolt group needed a tolerance of 0.00001

a 3 bolt group (0,0) (0,3) (0,6) load at (5,3) angle: 15 needed a tolerance of 0.1 on my end

I'm sure the scipy module may have something built in to handle these odd conditions.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

TTFN (ta ta for now)

I can do absolutely anything. I'm an expert! https://www.youtube.com/watch?v=BKorP55Aqvg

FAQ731-376: Eng-Tips.com Forum Policies forum1529: Translation Assistance for Engineers Entire Forum list http://www.eng-tips.com/forumlist.cfm

## RE: Python Solve Functions - Help For A Noobie

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

ICx = -0.662, ICy = -3.0299, Pu = 95.2908 (see screen-shot below).

One possible reason for the difference in results is that my code takes the eccentricity as being the perpendicular distance from the centroid of the bolt group to the line of action of the applied force, as shown in the diagrams in the first link posted by sticksandtriangles. You seem to be using an XY coordinate for the point of application, with Y = 0, and that would give a different eccentricity for any non-vertical load.

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

Edit:think the equivalent e on your end would be 1.2941I added a convergence graph to my gui here is what happens to my version of the Brandt algorithm if I keep the precision too tight, 0.000001:

vs a tol=0.001:

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

Now when I run the program i get an error that states "import scipy.optimize as sci" no module named optimize.

Any thoughts on what happened (it was working before)? I do not even know where to check to see where this going wrong. It looks like my console is no longer the same, so I might have moved directories or something?

S&T

## RE: Python Solve Functions - Help For A Noobie

S&T

## RE: Python Solve Functions - Help For A Noobie

I've added another chart showing the stability of the C factor across the calculation iterations. This can aid in making an educated decision on whether the smaller tolerances needed sometimes result in a C that is relatively stable or not

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

http://yakpol.net/BoltGroup_down.html

It uses the Excel Solver, but works pretty fast. It is set up with exactly same example as we are working on, except the factored bolt shear strength (Phi.Rn) is set to 27.06 kip.

To check against my code I set Ru to 27.06/0.75, and I corrected deltamax to 0.34 in (I had entered it as 0.43 in in the examples posted previously). With Y set to zero in the Yakpol spreadsheet the eccentricity for my code = X*cos(theta), where theta is the angle to the vertical. With those changes my results agree exactly with Yakpol's spreadsheet.

Celt83 - I tried your code, and using your ic_brandt function with final Icx and Icy values I get exact agreement with the first 4 results in the table output, but all force and moment results are lower by the Ru factor. I don't understand why you are treating Ru as a variable.

Compared with your brandt function, my results are completely different. Have you made significant changes to the posted code?

Finally a warning - first hit on my searches was a site called engineersviewpoint.blogspot. This seems to have been hijacked. I clicked on a link to an updated version of a post supposedly on Brandt's Method with VBA and immediately got pop-up messages that my hard drive was about to be erased.

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

Edit: oh all the fxi and fyi's will be off by Ru I did that multiplication at the end so not in the table values.I ment to get that corrected so it shows in the per bolt force table.

Edit2: this may be relevent

with the approach of Pult=1, then Rult = -Mp/sumMi, so my Mi table won't match yours but I've fixed the Fxi and Fyi table values to include Rult now.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

I misread your post, Rult is a variable as it is based on the bolt diameter and material. My current functions calculate everything relative to the ratio of the bolt forces to the ultimate force. Doing it this way you get the C multiplier for that bolt arrangement and can then back into a bolt size/material.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

## CODE --> Python

## CODE --> python

Not sure what the hang up is. I have this working on my home computer and I just installed python xy there and it works like a charm. Any help would be appreciated.

Thanks,

S&T

S&T

## RE: Python Solve Functions - Help For A Noobie

pip is a package manager used with python and should have been installed if you did a default install of python xy.

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

Doug Jenkins

Interactive Design Services

http://newtonexcelbach.wordpress.com/

## RE: Python Solve Functions - Help For A Noobie

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering

## RE: Python Solve Functions - Help For A Noobie

S&T

## RE: Python Solve Functions - Help For A Noobie

Open Source Structural Applications: https://github.com/buddyd16/Structural-Engineering