2

well frst of all I have one big project from mechanical engineering rolling at the moment. I need to construct and calculate whole crane construction and I am looking for help because I'm new in python.

It will be over 100 pages of calculations and equations that I'm programmed this way to give me final result and save latex ready code:

import math
from sympy import *
from sympy.solvers import solve
from sympy.physics.units import *

etau, ik, eta0 = symbols ("eta_u i_k eta_0")
eq1 = Eq(etau, (1/ik)*((1-eta0**ik)/(1-eta0)))
etau_result=eq1.rhs.evalf(subs={ik:3, eta0:98e-2})
eq1_R=solve(eq1)[0]

text_file = open("Output.txt", "w")
text_file.write("Stupanj djelovanja faktorskih koloturnika racuna se prema
formuli:\n \n"+"\\begin{equation} \n"+latex(eq1)+"=%s"%`    
(etau_result)+"\n"+"\\end{equation}" \
"\ngdje je: \n \n "\
+latex(ik)+"=u="+str(ik)+" -prijenosni omjer koloturnika\n"\
+latex(eta0)+" -Iskoristivost jedne uznice smjestene na valjnom lezaju\n\n"    
)

Ok please just ignore that strange language it's Croatian so I don't have time to translate that :)

Right now I have a ton of the same code which I need to write for every damn equation and downthere I need to make description that convert equations in latex form + give some words about exact equations.

I know that is impossible to automate part with description, but I want to automate part with equation because I need to write for every equation same code from line 5 to line 18 and thats pain in the a.... and takes too much time.

I hope that we will find some interesting solution.

Trevor Hickey
  • 36,288
  • 32
  • 162
  • 271
bubiZG
  • 21
  • 2
  • You might want to look at doing some templating. This will let you write just one big string, and insert in the unknown parts (the equations) programmatically. Python has a simple templating engine built in (like `'{stuff}'.format(stuff=1)`). There are more advanced once (the most common are jinja2 and mako). – asmeurer Nov 01 '16 at 19:04

1 Answers1

0

since I post here this qestion I came with something useful, but I need to improve it and at this point I don't know how:

a={}
n = input("How much keys do you want?")


#Input
for key in range(n):
    key = raw_input(" Write the name of the key  ")
    a.setdefault(key, [])
    a[key].append(raw_input(" Insert variable  "))
    a.setdefault(key, [])
    a[key].append(raw_input(" Insert symbole  "))
    a.setdefault(key, [])
    a[key].append(input(" Insert value  "))
#print a


#Sort
variable=[]
symbols1=[]
values=[]
for key, value in a.items():
    posX, posY, posZ = value
    variable.append(posX)
    symbols.append(posY)
    values.append(posZ)
#print variable
#print symbols1
#print values


#Math
variable = symbols(symbols1)
eq1 = Eq(etau, (1/ik)*((1-eta0**ik)/(1-eta0)))
print latex(eq1)

That gives me error

File "try.py", line 40, in

eq1 = Eq(etau, (1/ik)*((1-eta0**ik)/(1-eta0)))

NameError: name 'etau' is not defined

bubiZG
  • 21
  • 2