Python Calculator
Python Calculator
1 PythonCalculator (0.5.0)
1.1 Abstract
PythonCalculator is a simple OpenOffice.org extension that add
powerful Python calculator (Python´s eval function) in Writer.
This tool solve mathematical calculations and it´s single use:
1.2 Examples
A single math expression it´s replaced by evaluation result.
6+7,1*sqrt(25) → 41,5
A more complex math expression it´s replaced by math formula result.
x
y=a+b*sin(x/2)=2+3*sin(pi/2)= → y=ab⋅sin =23⋅sin =5,0
2 2
So as, if expression finish with equal symbol, result preserve expression. But, if expression no
finish with equal symbol, result replace expression.
2*sin(radians(90))-ln(2)^2= → 2⋅sinradians 90−ln 22=1,51954698608
2*sin(radians(90))-ln(2)^2 → 1,51954698608
Hello World!
import sys
print sys.executable
/usr/bin/python
# Partial differentiation
dx = diff(f, x)
dy = diff(f, y)
print 'dx =', dx
print 'dy =', dy
# Integration
print(integrate(f, x))
pprint(integrate(2*x + sinh(x), x))
print(integrate(f, (x, 0, pi/2)))
# Differential equations
x = Symbol('x')
f = Function('f')
print(f(x).diff(x, x) + f(x))
pprint(dsolve(f(x).diff(x, x) + f(x), f(x)))
# Algebraic equations
solve([x + 5*y - 2, -3*x + 6*y - 15], [x, y])
# Matrices
A = Matrix([[1,x], [y,1]])
pprint((A**2).subs(x, pi))
# Printing
alpha = Symbol('alpha')
text = latex(Integral(alpha*x**2, x))
# latex2oomath
dic ={'\\left(': ' left ( ',
'\\right)': ' right ) ',
'\\int': 'int',
'\\,': ' ',
'\\alpha': '%alfa'}
# replace all
for i, j in dic.iteritems():
text = text.replace(i, j)
print text
f = 5*x + y**2*sin(x)
5*pi/2 + y**2
8.85398163397448
dx = 5 + y**2*cos(x)
dy = 2*y*sin(x)
-y**2*cos(x) + 5*x**2/2
2
cosh(x) + x
y**2 + 5*pi**2/8
D(f(x), x, x) + f(x)
f(x) = C1*sin(x) + C2*cos(x)
[1 + pi*y 2*pi ]
[ ]
[ 2*y 1 + pi*y]
$int %alfa x^{2} dx$