Está en la página 1de 3

January 23, 2011

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 Write a mathematical expression.

2 Select that math expression.

3 Press PythonCalculator´s button for evaluate.

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=ab⋅sin  =23⋅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⋅sinradians 90−ln 22=1,51954698608
2*sin(radians(90))-ln(2)^2 → 1,51954698608

1.3 Mathematical functions


This extension support Python´s math functions. So as, for more information view:
http://docs.python.org/release/1.5.1p1/tut/calculator.html

© Copyright 2009, 2010, 2011 Jorge Rodríguez Araújo (grrodri@gmail.com)


January 23, 2011

1.4 Experimental feature


Embedded Python code is a experimental feature that add possibility of run Python code from
your OpenOffice.org Writer document. It´s useful for elaborate technical o scientific reports.
With this feature you add symbolic calculations in your Writer documents. So as:
OpenOffice.org + Python + Sympy... technical documents.
The Python code is identifier with paragraph styles, “Python input” for input code and “Python
output” for output code.
When you press PythonCalculator button, the block code identified by “Python input” is
executed and output is captured and inserted in the immediate block identified by “Python output”.
1.4.1 First probe
This is a first probe of Python embedded code in OpenOffice.org Writer.

# First code example


print 'Hello World!'

Hello World!

1.4.2 Python runtime


Replacing OpenOffice.org python runtime with your system's python installation, which may
contain more optional packages that you want to use in python.
http://udk.openoffice.org/python/python-bridge.html#replacing

import sys
print sys.executable

/usr/bin/python

1.4.3 Symbolic calculations


Now, it´s possible do symbolic calculations from your OpenOffice.org Writer with Python
embedded. Use Python and Sympy from OpenOffice.org Writer to solve mathematics problems, so as
differential and integral symbolic calculation.

# Import symbolic package


from sympy import *
# Define symbolic variables
x = Symbol('x')
y = Symbol('y')
# Define symbolic function
f = sin(x) * y ** 2 + 5 * x
print 'f =', f
# Substitute symbols
print f.subs(x, pi/2)
# Evaluate symbolic expression
print f.subs(x, pi/2).subs(y, 1).evalf()

© Copyright 2009, 2010, 2011 Jorge Rodríguez Araújo (grrodri@gmail.com)


January 23, 2011

# 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$

© Copyright 2009, 2010, 2011 Jorge Rodríguez Araújo (grrodri@gmail.com)

También podría gustarte