• No results found

To use SympyTeX, you have to run latex (or pdflatex) on your file, then python, and then latex again.

N/A
N/A
Protected

Academic year: 2021

Share "To use SympyTeX, you have to run latex (or pdflatex) on your file, then python, and then latex again."

Copied!
3
0
0

Bezig met laden.... (Bekijk nu de volledige tekst)

Hele tekst

(1)

SympyTeX example

Tim Molteno

August 16, 2011

1 Important! Setting up Your L A TEXenvironment

To use SympyTeX, you have to run latex (or pdflatex) on your file, then python, and then latex again.

latex example.tex python example.sympy latex example.tex

If you use Kile, or another L

A

TEXenvironment, you can set it up to automatically do the sympy python command as part of your build process.

2 Introduction

Using sympy within your L

A

TEXdocument is as easy as 2 + 2 = 4.

You can write a block, and then use the variables defined later in your code!

x = sympy.Symbol(’x’) h = sympy.integrate(1+x,x)

The variable h, how can be called using \sympy{h}, and you will get h = x+

12

x

2

. Similarly, the integral of 1 + x

4

is x +

15

x

5

.

3 sympyplain

The sympyplain command places the sympy output as text (rather than LaTeX formatted math stuff). This is really useful if the output is huge as formulae don’t line wrap.

The integral of 1 + x

4

is also x + x**5/5.

from sympy import * e = 1/cos(x)

The series expansion is 1 +

12

x

2

+

245

x

4

+

72061

x

6

+

8064277

x

8

+ O x

10

 .

tim@physics.otago.ac.nz

1

(2)

3.1 Invisibly sympy code

Placing a sympysilent block in your code, allows you do do things like define symbols without making a mess. The rotation matrix is through an angle θ around the z-axis is

R(θ) =



cos(θ) − sin(θ) 0 sin(θ) cos(θ) 0

0 0 1

 .

4 Plotting

Plotting works using the sympyplot command. This takes a matplotlib figure as a parameter. Have a look at the example below.

import matplotlib

import matplotlib.pyplot as plt

plt.matplotlib.rc(’text’, usetex = True) import pylab

fig = plt.figure()

ax = fig.add_subplot(111) t = pylab.linspace(0,10,400) ax.plot(t, sin(3*t), ’-’,

t, sin(0.3*t**2), ’--’, t, cos(t), ’-.’)

ax.legend((r’$A^{\omega}$’, r’$A^{2\omega}$’, r’$A^{3\omega}$’), shadow = False, loc = (0.75, 0.1))

ax.set_xlabel(r’$\gamma_1 + \gamma_2$’, {’fontsize’ : 20 }) ax.set_ylabel(r’$A^{n\omega}$ (dB)’, {’fontsize’ : 20 }) Here we’re using matplotlib! So this sympytex package is really not quite named properly.

The syntax is \sympyplot[<includegraphics opts>][fmt]{figure} where:

• fmt can be one of pdf,eps,png,jpg or many more. If it is omitted, then an appropriate choice will be made for you.

• <figure> is a matplotlib figure object

2

(3)

0 2 4 6 8 10

γ

1

+ γ

2

−1.0

−0.5 0.0 0.5 1.0

A

(dB)

Aω A A

Figure 1: The graph generated from \sympyplot[width=\linewidth]{fig}

3

Referenties

GERELATEERDE DOCUMENTEN

What is your goal, vision of how you think about how Quality management should be exercised in your company?. And how does this work

Russia is huge, so there are of course many options for you to visit, but don’t forget to really enjoy Moscow.. But don’t panic if you don’t understand how it works, just ask

Study Report – Russia - Saint Petersburg – Faculty of Liberal Arts and Sciences.. Last semester I had the opportunity to

Robin Cook would have had a better chance of beating Tony Blair to the Labour leadership had he looked more like Pierce Brosnan – or even, perhaps, a bit more like Tony Blair.. It

But it’s also true people aren’t telling the truth; they don’t want to tell the boss, “The reason I’m leaving is I hate you because you’re a terrible boss.” So instead

The idea presented here follows a standard LaTeX pattern – run LaTeX twice, once before Python, leaving breadcrumbs for Python to pickup during its run, then a final LaTeX run

To address this concern, this research introduces an integrative framework of the leader emergence theory in which the effects of creative behavior on perceived leader potential

The focus of this research will be on Dutch entrepreneurial ICT firms residing in the Netherlands that have received venture capital financing from at least one foreign