LaTeX Mathematics

Here is an equation without label using backslash-bracket environment:

$$ a = b + c $$

or with number and label, as in (12), using the equation environment:

$$ \begin{equation} {\partial u\over\partial t} = \nabla^2 u \tag{12} \end{equation} $$

We can refer to this equation by (12).

Here is a system without equation numbers, using the align-asterisk environment:

$$ \begin{align*} \pmb{a} &= \pmb{q}\times\pmb{n} \\ b &= \nabla^2 u + \nabla^4 v \end{align*} $$

And here is a system of equations with labels in an align environment:

$$ \begin{align} a &= q + 4 + 5+ 6 \tag{13} \\ b &= \nabla^2 u + \nabla^4 x \tag{14} \end{align} $$

We can refer to (13)-(14). They are a bit simpler than the Navier–Stokes equations. And test LaTeX hyphen in CG-2. Also test \( a_{i-j} \) as well as \( kx-wt \).

Testing alignat environment:

$$ \begin{alignat}{2} a &= q + 4 + 5+ 6\qquad & \mbox{for } q\geq 0 \tag{15} \\ b &= \nabla^2 u + \nabla^4 x & x\in\Omega \tag{16} \end{alignat} $$

More mathematical typesetting is demonstrated in the coming exercises.

Below, we have Problem 2: Flip a Coin and Project 4: Compute a Probability, as well as Project 5: Explore Distributions of Random Circles and Project 11: References in a headings do not work well in html, and in between there we have Exercise 10: Make references to projects and problems.

Exercises

Problem 2: Flip a Coin

a) Make a program that simulates flipping a coin \( N \) times. Print out "tail" or "head" for each flip and let the program count the number of heads.

Hint 1. Use r = random.random() and define head as r <= 0.5.

Hint 2. Draw an integer among \( \{1,2\} \) with r = random.randint(1,2) and define head when r is 1.

Answer. If the random.random() function returns a number \( < 1/2 \), let it be head, otherwise tail. Repeat this \( N \) number of times.

b) Vectorize the code in a) using boolean indexing.

Vectorized code can be written in many ways. Sometimes the code is less intuitive, sometimes not. At least there is not much to find in the section Section 1.

c) Vectorize the code in a) using numpy.sum.

Answer. np.sum(np.where(r <= 0.5, 1, 0)) or np.sum(r <= 0.5).

In this latter subexercise, we have an example where the code is easy to read.

My remarks

Remarks with such a subsubsection is treated as more text after the last subexercise. Test a list too:

    Mark 1.

    Mark 2.

Filenames: flip_coin.py, flip_coin.pdf.

Remarks

These are the exercise remarks, appearing at the very end.

Not an exercise

Should be possible to stick a normal section in the middle of many exercises.

Exercise 3: Test of plain text exercise

Very short exercise. What is the capital of Norway? Filename: myexer1.

Project 4: Compute a Probability

What is the probability of getting a number between 0.5 and 0.6 when drawing uniformly distributed random numbers from the interval \( [0,1) \)?

At the end we have a list because that caused problems in LaTeX in previous DocOnce versions:

    item1

    item2

Hint. To answer this question empirically, let a program draw \( N \) such random numbers using Python's standard random module, count how many of them, \( M \), that fall in the interval \( (0.5,0.6) \), and compute the probability as \( M/N \).

Project 5: Explore Distributions of Random Circles

The formula for a circle is given by

$$ \begin{align} x &= x_0 + R\cos 2\pi t, \tag{17}\\ y &= y_0 + R\sin 2\pi t, \tag{18} \end{align} $$

where \( R \) is the radius of the circle, \( (x_0,y_0) \) is the center point, and \( t \) is a parameter in the unit interval \( [0,1] \). For any \( t \), \( (x,y) \) computed from (17)-(18) is a point on the circle. The formula can be used to generate n points on a circle:

1
2
3
4
5
6
7
8
9
import numpy as np

def circle(R, x0, y0, n=501):
    t = np.linspace(0, 1, n)
    x = x0 + R*np.cos(2*np.pi*t)
    y = y0 + R*np.sin(2*np.pi*t)
    return x, y

x, y = circle(2.0, 0, 0)

The goal of this project is to draw \( N \) circles with random center and radius. Plot each circle using the circle function above.

a) Let \( R \) be normally distributed and \( (x_0,y_0) \) uniformly distributed.

Hint. Use the numpy.random module to draw the \( x_0 \), \( y_0 \), and \( R \) quantities.

Answer. Here goes the short answer to part a).

b) Let \( R \) be uniformly distributed and \( (x_0,y_0) \) normally distributed. Filename: norm.

c) Let \( R \) and \( (x_0,y_0) \) be normally distributed.

Filename: circles.

Remarks

At the very end of the exercise it may be appropriate to summarize and give some perspectives.

Exercise 6: Determine some Distance

Intro to this exercise. Questions are in subexercises below.

a) Subexercises are numbered a), b), etc.

Hint 1. First hint to subexercise a). With math \( a=b \) in hint:

$$ a=b. $$

And with code (in plain verbatim) returning \( x+1 \) in hint:

1
2
def func(x):
    return x + 1  # with code in hint

Hint 2. Second hint to subexercise a).

Test list in hint:

    item1

    item2

Filename: subexer_a.pdf.

Answer. Short answer to subexercise a). With math in answer: \( a=b \).

b) Here goes the text for subexercise b).

Some math \( \cos^2 x + \sin^2 x = 1 \) written one a single line:

$$ \cos^2 x + \sin^2 x = 1 \thinspace .$$

Hint. A hint for this subexercise.

Filename: subexer_b.pdf.

The text here belongs to the main (intro) part of the exercise. Need closing remarks to have text after subexercises.

Test list in exercise:

    item1

    item2

Remarks

Some final closing remarks, e.g. summarizing the main findings and their implications in other problems can be made. These remarks will appear at the end of the typeset exercise.

Some exercise without the "Exercise:" prefix

Just some text. And some math saying that \( e^0=1 \) on a single line, to test that math block insertion is correct:

$$ \exp{(0)} = 1 $$

And a test that the code lambda x: x+2 is correctly placed here:

1
lambda x: x+2

Exercise 8: Solution of differential equation

Given

$$ \frac{dy}{dx} = -y(x),\quad y(0)=1 $$

What is the solution of this equation?

Choice A: \( y=e^{-y} \)

Choice B: \( y=e^{y} \)

Choice C:
1
2
3
from math import exp
def f(x):
    return exp(x)

Choice D:

The solution cannot be found because there is a derivative in the equation.

Choice E:

The equation is meaningless: an equation must be an equation for \( x \) or \( y \), not a function \( y(x) \).


Example 9: Just an example

a) What is the capital of Norway?

Answer. Oslo.

Here goes another section

With some text, before we continue with exercises.

More Exercises

Exercise 10: Make references to projects and problems

Pick a statement from Project 5: Explore Distributions of Random Circles or Problem 2: Flip a Coin and verify it.

Test list at the end of an exercise without other elements (like subexercise, hint, etc.):

    item1

    item2

Filename: verify_formula.py.

Project 11: References in a headings do not work well in html

Refer to the previous exercise as Exercise 10: Make references to projects and problems, the two before that as Project 4: Compute a Probability and Project 5: Explore Distributions of Random Circles, and this one as Project 11: References in a headings do not work well in html. Filename: selc_composed.pdf.

References

    H. P. Langtangen and G. Pedersen. Propagation of Large Destructive Waves, International Journal of Applied Mechanics and Engineering, 7(1), pp. 187-204, 2002.

    H. P. Langtangen, K.-A. Mardal and R. Winther. Numerical Methods for Incompressible Viscous Flow, Advances in Water Resources, 25, pp. 1125-1146, 2002.

    H. P. Langtangen. Numerical Solution of First Passage Problems in Random Vibrations, SIAM Journal of Scientific and Statistical Computing, 15, pp. 997-996, 1994.

    K.-A. Mardal, G. W. Zumbusch and H. P. Langtangen. Software Tools for Multigrid Methods, Advanced Topics in Computational Partial Differential Equations -- Numerical Methods and Diffpack Programming, edited by H. P. Langtangen and A. Tveito, Springer, 2003, Edited book, http://some.where.org.

    H. P. Langtangen. The FEMDEQS Program System, Department of Mathematics, University of Oslo, 1989, http://www.math.uio.no/old/days/hpl/femdeqs.pdf.

    H. P. Langtangen. Stochastic Breakthrough Time Analysis of an Enhanced Oil Recovery Process, SIAM Journal on Scientific Computing, 13, pp. 1394-1417, 1992.

    M. Mortensen, H. P. Langtangen and G. N. Wells. A FEniCS-Based Programming Framework for Modeling Turbulent Flow by the Reynolds-Averaged Navier-Stokes Equations, Advances in Water Resources, 34(9), doi: 10.1016/j.advwatres.2011.02.013, 2011.

    S. Glimsdal, G. Pedersen, K. Atakan, C. B. Harbitz, H. P. Langtangen and F. L\ovholt. Propagation of the Dec. 26, 2004 Indian Ocean Tsunami: Effects of Dispersion and Source Characteristics, International Journal of Fluid Mechanics Research, 33(1), pp. 15-43, 2006.

    S. Rahman, J. Gorman, C. H. W. Barnes, D. A. Williams and H. P. Langtangen. Numerical Investigation of a Piezoelectric Surface Acoustic Wave Interaction With a One-Dimensional Channel, Physical Review B: Condensed Matter and Materials Physics, 74, 2006, 035308.

    J. B. Haga, H. Osnes and H. P. Langtangen. On the Causes of Pressure Oscillations in Low-Permeable and Low-Compressible Porous Media, International Journal of Analytical and Numerical Methods in Geomechanics, doi: 10.1002/nag.1062, 2011, http://onlinelibrary.wiley.com/doi/10.1002/nag.1062/abstract.

    H. P. Langtangen. Computational Partial Differential Equations - Numerical Methods and Diffpack Programming, second edition, Texts in Computational Science and Engineering, Springer, 2003.

    H. P. Langtangen. Python Scripting for Computational Science, third edition, Texts in Computational Science and Engineering, Springer, 2008.

    H. P. Langtangen and G. Pedersen. Finite Elements for the Boussinesq Wave Equations, Waves and Non-linear Processes in Hydrodynamics, edited by J. Grue, B. Gjevik and J. E. Weber, Kluwer Academic Publishers, pp. pp. 117-126, 1995, http://www.amazon.ca/Waves-Nonlinear-Processes-Hydrodynamics-John/dp/0792340310.

    H. P. Langtangen. A Primer on Scientific Programming With Python, third edition, Texts in Computational Science and Engineering, Springer, 2012.

    P. V. Jeberg, H. P. Langtangen and C. B. Terp. Optimization With Diffpack: Practical Example From Welding, Simula Research Laboratory, 2004, Internal report.

    H. P. Langtangen. Computational Methods for Two-Phase Flow in Oil Reservoirs, Ph.D. Thesis, Mechanics Division, Department of Mathematics, University of Oslo, 1989, Dr. Scient. thesis..

    H. P. Langtangen. Computational Modeling of Huge Tsunamis From Asteroid Impacts, 2007, Invited keynote lecture at the \emphInternational conference on Computational Science 2007 (ICCS'07), Beijing, China.

    H. P. Langtangen. Solution of the Navier-Stokes Equations With the Finite Element Method in Two and Three Dimensions, M.Sc. Thesis, Mechanics Division, Department of Mathematics, University of Oslo, 1985, Cand.Scient. thesis.

    H. P. Langtangen and A. Tveito. Numerical Methods in Continuum Mechanics, Center for Industrial Research, 1991, Lecture notes for a course (ME-IN 324). 286 pages..

    H. P. Langtangen. Diffpack: Software for Partial Differential Equations, Proceedings of the Second Annual Object-Oriented Numerics Conference (OON-SKI'94), Sunriver, Oregon, USA, edited by A. Vermeulen, 1994.

Appendix: Just for testing; part I

This is the first appendix.

A subsection within an appendix

Some text.

Appendix: Just for testing; part II

This is more stuff for an appendix.

Appendix: Testing identical titles

Without label.

Appendix: Testing identical titles

With label.

Appendix: Testing identical titles

What about inserting a quiz?

« Previous
Next »