What's new

Useful Software - Mechanical Expressions

RCH_Projects

Alibre Super User
Mechanical Expressions (ME) is a geometric application (much in the vein of GeoGebra viewtopic.php?f=1&t=6713&p=63856&hilit=geogebra#p63856) that includes export of math formulas for VBA, HTML5/Javascript apps and other math softwares. http://www.mechanicalexpressions.com/

ME is an extension of features of Geometry Expressions (http://geometryexpressions.com/)

Significantly to myself it includes kinematics with velocity, mass, and torque calculations.

It is weal in the areas of gears (none) and limited on splines.

Using formulas from ME imported into Excel (VBA or cell formulas) I can create general spline plots. I must use GoeGebra to derive a polynomial (up 19 degrees) for formula input back into ME.

Here ME falls short in that the splines are not integrated well into the application. Attachment to other geometry is limited for motion or calculation.

Otherwise it is a fantastic application. There are quirks but if you run into issue support is good and I may be able to help.

------------

Splines seem to be an Achilles heel in most applications. Please share any applications like this which integrate splines.

-------------

Aside from sharing info on the software anyone with insight on an issue I have would be appreciated (question languished on external forums).
Given x= 12.91054398 then y= 1.60632207 with the VBA code:

Code:
Sheet_Solve_y = (-4.40585822981928E-09 * T ^ 16#) + (5.74419717796372E-07 * T ^ 15#) - (3.46878254600578E-05 * T ^ 14#) + (1.28732045453625E-03 * T ^ 13#) - (3.28464894874479E-02 * T ^ 12#) + (0.610693781281248 * T ^ 11#) - (8.55392744958613 * T ^ 10#) + (92.0233061136475 * T ^ 9#) - (767.952783755359 * T ^ 8#) + (4984.31366665954 * T ^ 7#) - (25055.1684160808 * T ^ 6#) + (96421.9210677882 * T ^ 5#) - (278136.16460912 * T ^ 4#) + (580402.780587017 * T ^ 3#) - (824507.403253457 * T ^ 2#) + (710250.919414171 * T) - 278277.945692182

I need to use "y" to solve for "x" (trying to work around ME limitations).

Spent a lot of fractured time researching Software and personal solutions haven't turned up the correct reciprocal(?). Maybe the answer is simple and beneath contempt but care giving and home duties eat my lunch and I need solutions that are quick and repeatable. When I have a software solution I understand or can automate I'll be deeply grateful. Please illustrate answer or example sufficient for weak digestion :) .
 

ajayre

Alibre Super User
WizoScript can solve equations... but I don't see 'x' anywhere in your equation. Am I missing it? Instead I see 'T' and things like '16#' which I guess are spreadsheet cell references.

Also I am confused because you want to solve for 'x' but you already give a value for 'x' of 12.91054398.

If you can post the equation with values instead of cell references I can see if it can be solved for 'T' (rather than 'x'), if that is what you want.

Andy
 

RCH_Projects

Alibre Super User
Hello Andy,

I pulled the code from an Excel 10 VBA macro after pulling calculations from GeoGebra and/or "ME". This has been a long process. Perhaps I should have shown the entire Excel code.
Code:
Function Sheet_Solve_Derivative(T) As Double
 Sheet_Solve_Derivative = ((-7.04937316771086E-08) * T ^ 15#) + (8.61629576694557E-06 * T ^ 14#) + ((-4.8562955644081E-04) * T ^ 13#) + (1.67351659089712E-02 * T ^ 12#) + ((-0.394157873849375) * T ^ 11#) + (6.71763159409373 * T ^ 10#) + ((-85.5392744958613) * T ^ 9#) + (828.209755022827 * T ^ 8#) + ((-6143.62227004286) * T ^ 7#) + (34890.1956666168 * T ^ 6#) + ((-150331.010496485) * T ^ 5#) + (482109.605338941 * T ^ 4#) + ((-1112544.65843648) * T ^ 3#) + (1741208.34176105 * T ^ 2#) + ((-1649014.80650691) * T) + 710250.919414171
End Function

I did not clean up the code since (sometimes) it causes less problems when looking for help and other times more. Sometimes the more I say the more I confuse others so I "try" to work it through all I can.
I will continue at the risk of being verbose/annoying.

A more respectable Excel VBA code could be:
Code:
Function Sheet_Solve_for_Y(X) As Double

Sheet_Solve_for_Y = ((-7.04937316771086E-08) * X ^ 15) + (8.61629576694557E-06 * X ^ 14) + ((-4.8562955644081E-04) * X ^ 13) + (1.67351659089712E-02 * X ^ 12) + ((-0.394157873849375) * X ^ 11) + (6.71763159409373 * X ^ 10) + ((-85.5392744958613) * X ^ 9) + (828.209755022827 * X ^ 8) + ((-6143.62227004286) * X ^ 7) + (34890.1956666168 * X ^ 6) + ((-150331.010496485) * X ^ 5) + (482109.605338941 * X ^ 4) + ((-1112544.65843648) * X ^ 3) + (1741208.34176105 * X ^ 2) + ((-1649014.80650691) * X) + 710250.919414171

End Function

"T" was only used because in "ME" it is the standard variable and I try to keep code similar between software packages. Here is an "ME" example of a "similar" spline:


... and the "#" symbol is an "ME" or Excel "artifact" that I left alone since "15" and "15#" is only an integer value to Excel. No cell references involved as the values of "x" are passed into the function although "x" referenced as "T" in the function.

... starting with a value of 12.91054398 for 'x' the function gave me y= 1.60632207. The 1.606 (rounded) is the separation of two parts. I need to enter 1.606 and many other values for "y".

(background) -----
In GeoGebra the spline is plotted using x,y coordinates from Excel and used to derive the polynomial/parametric function for "y" (swapping x,y for GeoGebra does not work correctly or I wouldn't have an issue).
I use GeoGebra because it is the only software I have found that gives me the parametric/polynomial function from the Excel x,y coordinates.
The GeoGebra function plots the spline in "ME" but "ME" doesn't integrate calculations for movement along the spline or even move the spline in relation to other movement.

Therefore I must find the function in Excel that uses the mechanical separation between the two parts ("y") to determine the "x" location of the 3rd part (spline) between them (think of a wedge drive between two parts, but not so trivial an application).

The process has been to construct the geometry in "ME" with a straight spline (just a line), transfer code to Excel, approximate xy spline plot for altered motion, save xy plot in GeoGebra, derive parametric function in GeoGebra for closest fit of plot.

Ideally the parametric equation would be entered back into "ME" and the results analyzed. But in "ME" the spline from a function is more for geometric "study" rather than a component of a machine design.

As a result I have to incorporate a solution strictly in Excel where I have to "start" by the separation between two parts ("y") and determine "x" for the location of the 3rd part "y" between them so I can calculate actual slope at that point. At the end of that I will probably redesign the initial estimated spline as needed and go again.

There are no "textbook" examples in geometry or engineering and/or total software package to do it all. So I use the best of any software and keep plugging away. Just so little undistracted time for things here at home.
(end background) -----

The value for "y" will be generated in Excel and I will need "x" calculated. If WizoScript can produce a formula/function that would be ideal. (phew, long day).

Looking for something in the vein of:
Code:
Function Sheet_Solve_for_X(Y) As Double

Sheet_Solve_for_X = ?

End Function
WizoScript version or otherwise is fine.

With only a function for "x" when I only know the value of "y" what the function/value of "x" is.

In the end viable parts will all get integrated into the Geomagic (mechanical) CAD design(s) I am trying to finish (these many years).

Strictly the equation for "y" with values:
Code:
Y = ((-7.04937316771086E-08) * X ^ 15) + (8.61629576694557E-06 * X ^ 14) + ((-4.8562955644081E-04) * X ^ 13) + (1.67351659089712E-02 * X ^ 12) + ((-0.394157873849375) * X ^ 11) + (6.71763159409373 * X ^ 10) + ((-85.5392744958613) * X ^ 9) + (828.209755022827 * X ^ 8) + ((-6143.62227004286) * X ^ 7) + (34890.1956666168 * X ^ 6) + ((-150331.010496485) * X ^ 5) + (482109.605338941 * X ^ 4) + ((-1112544.65843648) * X ^ 3) + (1741208.34176105 * X ^ 2) + ((-1649014.80650691) * X) + 710250.919414171

So, thanks for looking!!!!!!
 

Attachments

  • ME Parametric Function 2.png
    ME Parametric Function 2.png
    9.5 KB · Views: 511

ajayre

Alibre Super User
I can't help you - sorry. OK, that's the bad news out of the way.

WizoScript contains a third-party symbolic computation library called "Sympy", which can solve equations. Note that "powers of" in Python are "**" rather than "^" which you commonly see elsewhere.

Here is the closest I was able to get:

Code:
import sympy
from sympy import *
import math

y = Symbol('y')
T = Symbol('T')

y = 1.60632207

Equation = Eq(((482109.605338941) * T**4) + ((-1112544.65843648) * T**3) + (1741208.34176105 * T**2) + ((-1649014.80650691) * T) + 710250.919414171, (y))

print Equation

TValue = solve(Equation)[0]
print TValue

This produces a complex number, I guess because I've only gone as high as the fourth order of your polynomial equation. This is because after doing some research Sympy cannot solve equations higher than four orders, and yours has fifteen.

I think that either your equation is not solvable, or requires a supercomputer.

My suggestion is to look at the minimum accuracy you require for the real-world and simplify your equation to meet that goal. Or alternatively use a numerical approach instead.

For any help with using Sympy further I suggest you post on their mailing list, as I don't know a great deal about it.

Andy
 

RCH_Projects

Alibre Super User
LOL, thanks for looking at it. Never thought I could "choke" a computer though and here I thought the Geometers out there had everything in the world figured out and squared away.

Minimum accuracy is a chicken and egg kind of thing. The (current) pattern has some relatively tight constraints (weird but fantastic).
Minimum accuracy was going to be the "fitted" spline.

Numerical approach? y = 3x - 5;

x = 4;
y = 3 * 4 - 5;
y = 7


so;
y + 5 = 3 * x;
7 + 5 = 3 * 4
and;
(5 + y) / 3 = x
(5 + 7) / 3 = 4

That what you mean?

If that will work I need a little more advanced lesson in algebra. How to treat powers and parenthesis? I can write code to parse/juggle an equation. I don't know if it has ever been done but if it can be done I would be surprised to be the first or only one to do it.

The y = 3x - 5 example is about as complex as I can tackle or find an example of (earlier I searched for days at a time (off and on for weeks) for better instructions in this area but never found any lesson remotely this complex). Then some websites or video instructors just start skipping steps they know by heart and assume the reader or viewer does too. :roll: I just want to get done. :cry:

I'll research Sympy but if anyone can post a manual example of this approach with my equation (so I can code with it) or post link(s) to more informative instructions (clearer, more complete set of transformation rules) or even a website savvy enough to answer this issue, I'll tip my hat to them and credit them in related code.

In a rut like this I remind myself of the saying "Even a blind squirrel finds a nut once in a while" and keep groping.

Any replies are good. This, as always, is going to take a while no matter what as focused care giving is a must. You'll know if I have a good lead/solution cause I'll share here anyway. :wink:
 

ajayre

Alibre Super User
If I put a value of T = 12.91054398 into your equation I get y = 0.0322159575298, not the value you gave.

Andy
 

ajayre

Alibre Super User
Here is the numerical solution. Can you explain how it works? :)

Code:
from __future__ import division
import math
from math import *

def Func(T):
  y = ((-7.04937316771086E-08) * (T**15)) + (8.61629576694557E-06 * (T**14)) + ((-4.8562955644081E-04) * (T**13)) + (1.67351659089712E-02 * (T**12)) + ((-0.394157873849375) * (T**11)) + (6.71763159409373 * (T**10)) + ((-85.5392744958613) * (T**9)) + (828.209755022827 * (T**8)) + ((-6143.62227004286) * (T**7)) + (34890.1956666168 * (T**6)) + ((-150331.010496485) * (T**5)) + (482109.605338941 * (T**4)) + ((-1112544.65843648) * (T**3)) + (1741208.34176105 * (T**2)) + ((-1649014.80650691) * T) + 710250.919414171
  return y

# value we want to solve for
TargetY = 1.60632207

# search range for T
T_min = 0.0
T_max = 10.0

# max number of times we calculate
# higher value = more accuracy
Iterations = 100

# perform calculation
for Iteration in range(1, Iterations + 1):
  T = ((T_max - T_min) / 2.0) + T_min
  y = Func(T)
  print "%d: T_max = %.8f, T_min = %.8f, T = %.8f, y = %.8f" % (Iteration, T_max, T_min, T, y)
  if round(y, 8) == round(TargetY, 8):
    break;
  elif y < TargetY:
    T_max = T
  elif y > TargetY:
    T_min = T

# show final result
print "T = %.8f for y = %.8f" % (T, y)

Code:
1: T_max = 10.00000000, T_min = 0.00000000, T = 5.00000000, y = 0.00877487
2: T_max = 5.00000000, T_min = 0.00000000, T = 2.50000000, y = -219.30654963
3: T_max = 2.50000000, T_min = 0.00000000, T = 1.25000000, y = 23091.09402558
4: T_max = 2.50000000, T_min = 1.25000000, T = 1.87500000, y = 1757.71600540
5: T_max = 2.50000000, T_min = 1.87500000, T = 2.18750000, y = 86.01549057
6: T_max = 2.50000000, T_min = 2.18750000, T = 2.34375000, y = -150.79607350
7: T_max = 2.34375000, T_min = 2.18750000, T = 2.26562500, y = -61.03782606
8: T_max = 2.26562500, T_min = 2.18750000, T = 2.22656250, y = 4.14657803
9: T_max = 2.26562500, T_min = 2.22656250, T = 2.24609375, y = -30.37195066
10: T_max = 2.24609375, T_min = 2.22656250, T = 2.23632813, y = -13.61339927
11: T_max = 2.23632813, T_min = 2.22656250, T = 2.23144531, y = -4.86104634
12: T_max = 2.23144531, T_min = 2.22656250, T = 2.22900391, y = -0.38945448
13: T_max = 2.22900391, T_min = 2.22656250, T = 2.22778320, y = 1.87046750
14: T_max = 2.22900391, T_min = 2.22778320, T = 2.22839355, y = 0.73848785
15: T_max = 2.22839355, T_min = 2.22778320, T = 2.22808838, y = 1.30397240
16: T_max = 2.22808838, T_min = 2.22778320, T = 2.22793579, y = 1.58709356
17: T_max = 2.22793579, T_min = 2.22778320, T = 2.22785950, y = 1.72874892
18: T_max = 2.22793579, T_min = 2.22785950, T = 2.22789764, y = 1.65791334
19: T_max = 2.22793579, T_min = 2.22789764, T = 2.22791672, y = 1.62250147
20: T_max = 2.22793579, T_min = 2.22791672, T = 2.22792625, y = 1.60479702
21: T_max = 2.22792625, T_min = 2.22791672, T = 2.22792149, y = 1.61364912
22: T_max = 2.22792625, T_min = 2.22792149, T = 2.22792387, y = 1.60922304
23: T_max = 2.22792625, T_min = 2.22792387, T = 2.22792506, y = 1.60701002
24: T_max = 2.22792625, T_min = 2.22792506, T = 2.22792566, y = 1.60590352
25: T_max = 2.22792566, T_min = 2.22792506, T = 2.22792536, y = 1.60645677
26: T_max = 2.22792566, T_min = 2.22792536, T = 2.22792551, y = 1.60618014
27: T_max = 2.22792551, T_min = 2.22792536, T = 2.22792543, y = 1.60631846
28: T_max = 2.22792543, T_min = 2.22792536, T = 2.22792540, y = 1.60638761
29: T_max = 2.22792543, T_min = 2.22792540, T = 2.22792542, y = 1.60635303
30: T_max = 2.22792543, T_min = 2.22792542, T = 2.22792543, y = 1.60633575
31: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632710
32: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632278
33: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632062
34: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632170
35: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632224
36: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632197
37: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632210
38: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632204
39: T_max = 2.22792543, T_min = 2.22792543, T = 2.22792543, y = 1.60632207
T = 2.22792543 for y = 1.60632207

The solution for y = 1.60632207 is T = 2.22792543

Takes only a few seconds to find the solution. This only works if there is exactly one solution.

Andy
 

RCH_Projects

Alibre Super User
ajayre said:
If I put a value of T = 12.91054398 into your equation I get y = 0.0322159575298, not the value you gave.

Andy

You're right. Only my first post referred to the correct equation. I got sidetracked (over and over) and then started using an equation from a "derivative" equation subroutine below the right equation (.03188). Doh!!

ajayre said:
Here is the numerical solution. Can you explain how it works? :)

Ahh! (Elegant) brute force!

Initial appraisal I would say Iteration hashing(?) potential "x" values to find nearest value to the "y" value target. Reminds me of a bubble sort.

Much like my abysmal math skills, I'm rusty on some software terminology but you know what I mean (or at least I know what you mean).
If I enter the correct equation for "y" in "Func(T)" it would no doubt give me something like the original 12.9105 value.

OK! I'll put a peg on your solution and get back to my development crawl (so slow I forget half the things I've already done).

I deeply appreciate the answer and your 8) time.

Roger
 
Top