2

Last week I read a short paper on LaTeX and now I'm writing my first document. I've googled and fixed most problems but this one I haven't found any working answer to. It's for a math assignment and I just want to write lots of math with a few \text{} comments in each solution so my document looks like:

\documentclass[11pt,twoside,a4paper,fleqn]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[swedish, english]{babel}
\usepackage{mathtools} 
\usepackage{amssymb}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.5}
\lhead{Fredrik \qquad 2/5-2015}
\rhead{Inlämningsuppgift 2}
\setlength{\oddsidemargin}{15.5pt}
\setlength{\evensidemargin}{15.5pt}
\setlength{\headheight}{14pt}
\begin{document}
\section*{Uppgift 2.1}
\begin{equation*}
\begin{split}
& u(x,y)=\sqrt{x^2+y^2} \\
& u_{1}=\frac{2x}{2\sqrt{x^2+y^2}}=\frac{x}{\sqrt{x^2+y^2}}, \quad
u_{2}=\frac{2y}{2\sqrt{x^2+y^2}}=\frac{x}{\sqrt{x^2+y^2}} \\
& \nabla u(1,1)=\frac{1}{\sqrt{2}}i+\frac{1}{\sqrt{2}}j, \quad
|\nabla u|=\sqrt{\left( \frac{1}{\sqrt{2}}\right) ^2 + \left( \frac{1}{\sqrt{2}} \right)^2}=\sqrt{\frac{1}{2}+\frac{1}{2}}=1 \\
& v(x,y)=x+y+2\sqrt{xy} \\
& v_{1}=1+\frac{2y}{2\sqrt{xy}}=1+\frac{y}{\sqrt{xy}}, \quad
v_{2}=1+\frac{2x}{2\sqrt{xy}}=1+\frac{x}{\sqrt{xy}} \\
& \nabla v(1,1)=2i+2j, \quad
|\nabla v|=\sqrt{4+4}=2\sqrt{2} \\
& \text{Grader } \theta \text{ mellan \textbf{u} och \textbf{v}:} \\ 
& \theta = \arccos \frac{u\bullet v}{|u||v|} \\
& \theta = \arccos \left( \frac{\frac{2}{\sqrt{2}}+\frac{2}{\sqrt{2}}}{2\sqrt{2}} \right)=\arccos \left(\frac{4}{2\sqrt{2}\sqrt{2}} \right)=\arccos(1)=0
\end{split} 
\end{equation*}

\section*{Uppgift 2.2}
\begin{equation*}
\begin{split}
& r=a+b, \quad |r|=\sqrt{a^2+b^2}, \quad \nabla r=ai+bj \\
& u=\sin \left( \sqrt{a^2+b^2} \right), \quad u_{1}=\frac{a \cdot \cos \left( \sqrt{a^2+b^2} \right) }{2\sqrt{a^2+b^2}}, \quad u_{2}=\frac{b \cdot \cos \left( \sqrt{a^2+b^2} \right) }{2\sqrt{a^2+b^2}} \\
& \nabla u=\frac{\cos \left( \sqrt{a^2+b^2} \right)}{\sqrt{a^2+b^2}}\left(ai+bj \right) \\
& \frac{ai+bj}{\sqrt{a^2+b^2}}\bullet \frac{\cos \left( \sqrt{a^2+b^2} \right)}{\sqrt{a^2+b^2}}(ai+bj)=\frac{\cos \left( \sqrt{a^2+b^2} \right)\cdot a^2}{a^2+b^2}+\frac{\cos \left( \sqrt{a^2+b^2} \right)\cdot b^2}{a^2+b^2}= \\
& \frac{\cos \left( \sqrt{a^2+b^2} \right)\cdot (a^2+b^2)}{a^2+b^2}= \cos \left( \sqrt{a^2+b^2} \right)=\cos (r)
\end{split}
\end{equation*}

\section*{Uppgift 2.3}
\begin{equation*}
\begin{split}
& z(x,y)=6x^2 y^3-6x^2-9y^2+1, \quad \nabla z=(12xy^3-12x, 18x^2 y^2-18y)\\
& \text{Letar efter nollställen}\\
& 12x(y^3-1)=0, \quad y=0, \quad x=0 \qquad \ \text{ger } (0,0)\\
& 18y(x^2y-1)=0, \quad y=0, \quad x=\pm 1 \quad \text{ger } (1,1) \text{ och } (-1,1)\\
& z_{xx}=12y^3-12, \quad z_{xy}=z_{yx}=36xy^2, \quad z_{yy}=36x^2y-8\\
& \mathcal{H}=
\begin{bmatrix}
z_{xx} & z_{xy}\\
z_{yx} & z_{yy}
\end{bmatrix}
=
\begin{bmatrix}
12y^3-12 & 36xy^2\\
36xy^2 & 36x^2 y-18
\end{bmatrix} \\
& (0,0): \mathcal{H} =
\begin{bmatrix}
-12 & 0\\
0 & -18
\end{bmatrix}
\quad det(\mathcal{H})=(-12)\cdot(-18)-0=126 \\
& \begin{rcases}
det(\mathcal{H}) & > 0\\
f_{xx} & < 0
\end{rcases}
\text{Maxpunkt} \\
& (1,1): \mathcal{H} =
\begin{bmatrix}
0 & 36\\
36 & 18
\end{bmatrix}
\quad det(\mathcal{H})=0-36 \cdot 36=-1296 
&&\quad det(\mathcal{H}) < 0 \\
& (-1,1): \mathcal{H} =
\begin{bmatrix}
0 & -36\\
-36 & 18
\end{bmatrix}
\quad det(\mathcal{H})=0-(-36) \cdot (-36)=-1296
&&\quad det(\mathcal{H}) < 0 
\end{split}
\end{equation*}

\section*{Uppgift 2.4}
\begin{equation*}
\begin{split}
& f(x,y)=2x+8y-x^2-4y^2-4, \quad \nabla f=(2-2x, 8-8y) \\
& (1,1): \quad
\begin{rcases}
f_{xx} & =-2 \\
det(\mathcal{H})& =16
\end{rcases}
\text{maxpunkt}
\end{split}
\end{equation*}

\section*{Uppgift 2.5}
\begin{equation*}
\begin{split}
& f(x,y)=\sqrt{2x^2+3y^2+4} \\
& 000\text{Första delen}000 \\
& f_1 = \frac{4x}{2\sqrt{2x^2+3y^2+4}}, \quad
f_2 = \frac{6y}{2\sqrt{2x^2+3y^2+4}}, \quad 
f_{12}=f_{21}=\frac{-2x6y}{\left( \sqrt{2x^2+3y^2+4} \right)^2} \\
\\
& f_{11} = \frac{2\sqrt{2x^2+3y^2+4}-\frac{2x\cdot 4x}{2\sqrt{2x^2+3y^2+4}}}{\left( 2\sqrt{2x^2+3y^2+4} \right)^2}, \quad
f_{22}= \frac{3\sqrt{2x^2+3y^2+4}-\frac{3y\cdot 6y}{2\sqrt{2x^2+3y^2+4}}}{\left( 2\sqrt{2x^2+3y^2+4} \right)^2} \\ \\
& \text{Kollar värden för derivatorna i punkten $(0,0)$} \\
& f_1=\frac{0}{2}=0, \quad f_2=\frac{0}{2}=0, \quad f_{12}=0, \quad 
f_{11}=\frac{2\cdot 2-0}{4}=1, \quad f_{22}=\frac{3\cdot 2-0}{4}=\frac{3}{2} \\
& P_2(x,y)= f(a,b)+f_1(a,b)(x-a)+f_2(a,b)(y-b)+\frac{1}{2} \left( f_{11}(x-a)^2+f_{22}(y-b)^2+2f_{12}(x-a)(y-b)\right) \\
\end{split}
\end{equation*}
\begin{equation*}
\begin{split}
& P_2(x,y)=2+0x+0y+\frac{1}{2}(x-0)^2+\frac{1}{2}\cdot\frac{3}{2}(y-0)^2+\frac{1}{2}\cdot2\cdot0(x-0)(y-0)=2+\frac{1}{2}x^2+\frac{3}{4}y^2 \\
& P_2(0,1;0,1)=2+\frac{1}{2}(0,1)^2+\frac{3}{4}(0,1)^2=2+\frac{1}{200}+\frac{3}{400}=\frac{805}{400}=2,0125 \\
& f(0,1;0,1)=\sqrt{2(0,1)^2+3(0,1)^2+4}=\sqrt{\frac{2}{100}+\frac{3}{100}+4}=\sqrt{\frac{405}{100}}=2,01246 \\
\end{split}
\end{equation*}

\section*{Uppgift 2.6}
\begin{equation*}
\begin{split}
& f(x,y)=2x+y, \quad g(x,y)=x^2+y^2-5=0 \\
& L(x,y,\lambda)=f(x,y)+\lambda g(x,y)=2x+y+\lambda (x^2+y^2-5) \\
& \frac{\partial L}{\partial x}=2+2x\lambda, \quad
\frac{\partial L}{\partial y}=1+2y\lambda, \quad
\frac{\partial L}{\partial \lambda}=x^2+y^2-5 \\
& \text{Söker efter nollställen genom att sätta derivatorna lika med 0} \\
& \begin{rcases} & \frac{\partial L}{\partial x}= 0=2(1+x\lambda) \Rightarrow \lambda=-\frac{1}{x}  \\
& \frac{\partial L}{\partial y}=0=1+2y\lambda \Rightarrow \lambda =-\frac{1}{2y} 
\end{rcases} \Rightarrow
-\frac{1}{x}=-\frac{1}{2y} \Rightarrow 2y=x \Rightarrow y=\frac{x}{2} \\
& \text{Sätter in resultatet i $\frac{\partial L}{\partial \lambda}=0$} \\
& 0=y^2+x^2-5 \Rightarrow \frac{x^2}{4}+x^2-5=0 \Rightarrow 0=5x^2-20 \Rightarrow 
4=x^2 \Rightarrow x=\pm 2 \\
& \text{Det ger} \\
& y=\frac{\pm2}{2}=\pm1 \text{ och } \lambda=\pm \frac{1}{2} \\
& \text{Ur det får vi punkterna $(2,1)$ och $(-2,-1)$ vilket ger} \\
& f(2,1)=4+1=5 \quad \text{och} \quad f(-2,-1)=-4-1=-5 \\
\end{split}
\end{equation*}

\end{document}

This gives me an output where the spacing above and below the section headings differ (they indent differently too but that's not as important):

part of pdf output

  • Welcome to TeX.SX! Please make your code compilable (if possible), or at least complete it with \documentclass{...}, the required \usepackage's, \begin{document}, and \end{document}. That may seem tedious to you, but think of the extra work it represents for TeX.SX users willing to give you a hand. Help them help you: remove that one hurdle between you and a solution to your problem. – Mike Renfro May 2 '15 at 16:06
  • LaTeX is working hard to keep sections with the following material but it has not got much to work on here - hence it stretches in the "least bad" place. You can either add more text - or you can use something other than \section for the headings. Also search for questions here about \raggedbottom... – Thruston May 2 '15 at 16:08
  • Please fix the question so that the posted code matches the posted image. – David Carlisle May 2 '15 at 16:17
  • Sorry, didn't get how to add code so did 4 spaces manually on each row. Now all code is there. – user4499155 May 2 '15 at 16:32
  • 1
    the split sub-environment is always handled as an unbreakable box. to get rid of that, replace equation* by align*, remove \begin{split} and \end{split}, and insert \allowdisplaybreaks in your preamble. since you have begun every display line with &, that will keep every line flush left. you will still have many problems with lines too long. (this is a comment and not an answer because i am having problems with the encoding, so can't reproduce the example without (irrelevant) errors.) – barbara beeton May 2 '15 at 17:04
0

Here is a solution. I slightly simplified your code with the geometry package and improved the formatting of decimal numbers with siunitx

\documentclass[11pt, twoside, a4paper, fleqn]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[swedish,english]{babel}%
\usepackage[showframe, nomarginpar, headheight=14pt, hmargin=30mm]{geometry}
\usepackage{mathtools}
\usepackage{amssymb}
\usepackage{fancyhdr}
\pagestyle{fancy}
\usepackage[nodisplayskipstretch]{setspace}
\setstretch{1.5}
\lhead{Fredrik \qquad 2/5-2015}
\rhead{Inlämningsuppgift 2}
\usepackage{siunitx}
\sisetup{input-decimal-markers={,},output-decimal-marker={,}}
\raggedbottom
\allowdisplaybreaks


\begin{document}

\section*{Uppgift 2.1}

\vskip-\abovedisplayskip
\begin{align*}
    & u(x,y)=\sqrt{x^2+y^2} \\
    & u_{1}=\frac{2x}{2\sqrt{x^2+y^2}}=\frac{x}{\sqrt{x^2+y^2}}, \quad
  u_{2}=\frac{2y}{2\sqrt{x^2+y^2}}=\frac{x}{\sqrt{x^2+y^2}} \\
    & \nabla u(1,1)=\frac{1}{\sqrt{2}}i+\frac{1}{\sqrt{2}}j, \quad
  |\nabla u|=\sqrt{\left( \frac{1}{\sqrt{2}}\right) ^2 + \left( \frac{1}{\sqrt{2}} \right)^2}=\sqrt{\frac{1}{2}+\frac{1}{2}}=1 \\
    & v(x,y)=x+y+2\sqrt{xy} \\
    & v_{1}=1+\frac{2y}{2\sqrt{xy}}=1+\frac{y}{\sqrt{xy}}, \quad
  v_{2}=1+\frac{2x}{2\sqrt{xy}}=1+\frac{x}{\sqrt{xy}} \\
    & \nabla v(1,1)=2i+2j, \quad
  |\nabla v|=\sqrt{4+4}=2\sqrt{2} \\
    & \text{Grader } \theta \text{ mellan \textbf{u} och \textbf{v}:} \\
    & \theta = \arccos \frac{u\bullet v}{|u||v|} \\
    & \theta = \arccos \left( \frac{\frac{2}{\sqrt{2}}+\frac{2}{\sqrt{2}}}{2\sqrt{2}} \right)=\arccos \left(\frac{4}{2\sqrt{2}\sqrt{2}} \right)=\arccos(1)=0
\end{align*}

\section*{Uppgift 2.2}

\vskip-\abovedisplayskip
\begin{align*}
    & r=a+b, \quad |r|=\sqrt{a^2+b^2}, \quad \nabla r=ai+bj \\
    & u=\sin \left( \sqrt{a^2+b^2} \right), \quad u_{1}=\frac{a \cdot \cos \left( \sqrt{a^2+b^2} \right) }{2\sqrt{a^2+b^2}}, \quad u_{2}=\frac{b \cdot \cos \left( \sqrt{a^2+b^2} \right) }{2\sqrt{a^2+b^2}} \\
    & \nabla u=\frac{\cos \left( \sqrt{a^2+b^2} \right)}{\sqrt{a^2+b^2}}\left(ai+bj \right) \\
    & \frac{ai+bj}{\sqrt{a^2+b^2}}\bullet \frac{\cos \left( \sqrt{a^2+b^2} \right)}{\sqrt{a^2+b^2}}(ai+bj)=\frac{\cos \left( \sqrt{a^2+b^2} \right) \cdot a^2}{a^2+b^2}+\frac{\cos \left( \sqrt{a^2+b^2} \right) \cdot b^2}{a^2+b^2} \\
    & \qquad = \frac{\cos \left( \sqrt{a^2+b^2} \right) \cdot (a^2+b^2)}{a^2+b^2}= \cos \left( \sqrt{a^2+b^2} \right)=\cos (r)
\end{align*}

\section*{Uppgift 2.3}

\vskip-\abovedisplayskip
\begin{alignat*}{2}
  & z(x,y)=6x^2 y^3-6x^2-9y^2+1, \quad \nabla z=(12xy^3-12x, 18x^2 y^2-18y)\\
  & \text{Letar efter nollställen}\\
  & 12x(y^3-1)=0, \quad y=0, \quad x=0 \qquad \ \text{ger } (0,0)\\
  & 18y(x^2y-1)=0, \quad y=0, \quad x=\pm 1 \quad \text{ger } (1,1) \text{ och } (-1,1)\\
  & z_{xx}=12y^3-12, \quad z_{xy}=z_{yx}=36xy^2, \quad z_{yy}=36x^2y-8\\
  & \mathcal{H}=
  \begin{bmatrix}
  z_{xx} & z_{xy}\\
  z_{yx} & z_{yy}
  \end{bmatrix}
  =
  \begin{bmatrix}
  12y^3-12 & 36xy^2\\
  36xy^2 & 36x^2 y-18
  \end{bmatrix} \\
  & (0,0): \mathcal{H} =
  \begin{bmatrix}
  -12 & 0\\
  0 & -18
  \end{bmatrix}
  \quad \det(\mathcal{H})=(-12) \cdot (-18)-0=126 \\
  & \begin{rcases}
  \det(\mathcal{H}) & > 0\\
  f_{xx} & < 0
  \end{rcases}
  \text{Maxpunkt} \\
  & (1,1): \mathcal{H} =
  \begin{bmatrix}
  0 & 36\\
  36 & 18
  \end{bmatrix}
  \quad \det(\mathcal{H})=0-36 \cdot 36=-1296
    & & \det(\mathcal{H}) < 0 \\
  & (-1,1): \mathcal{H} =
  \begin{bmatrix}
  0 & -36\\
  -36 & 18
  \end{bmatrix}
  \quad \det(\mathcal{H})=0-(-36) \cdot (-36)=-1296
    & \enspace & \det(\mathcal{H}) < 0
\end{alignat*}

\section*{Uppgift 2.4}

\vskip-\abovedisplayskip
\begin{align*}
                    & f(x,y)=2x+8y-x^2-4y^2-4, \quad \nabla f=(2-2x, 8-8y) \\
                    & (1,1): \quad
  \begin{rcases}
  f_{xx} & =-2 \\
  \det(\mathcal{H}) & =16
  \end{rcases}
  \text{maxpunkt}
\end{align*}

\section*{Uppgift 2.5}

\vskip-\abovedisplayskip
\begin{align*}
  & f(x,y)=\sqrt{2x^2+3y^2+4} \\
  & 000\text{Första delen}000 \\
  & f_1 = \frac{4x}{2\sqrt{2x^2+3y^2+4}}, \quad f_2 = \frac{6y}{2\sqrt{2x^2+3y^2+4}}, \quad
  f_{12}=f_{21}=\frac{-2x6y}{\left( \sqrt{2x^2+3y^2+4} \right)^2} \\
  \\
  & f_{11} = \frac{2\sqrt{2x^2+3y^2+4}-\frac{2x \cdot 4x}{2\sqrt{2x^2+3y^2+4}}}{\left( 2\sqrt{2x^2+3y^2+4} \right)^2}, \quad
  f_{22}= \frac{3\sqrt{2x^2+3y^2+4}-\frac{3y \cdot 6y}{2\sqrt{2x^2+3y^2+4}}}{\left( 2\sqrt{2x^2+3y^2+4} \right)^2} \\ \\
  & \text{Kollar värden för derivatorna i punkten $(0,0)$} \\
  & f_1=\frac{0}{2}=0, \quad f_2=\frac{0}{2}=0, \quad f_{12}=0, \quad
  f_{11}=\frac{2 \cdot 2-0}{4}=1, \quad f_{22}=\frac{3 \cdot 2-0}{4}=\frac{3}{2} \\
    & \!\begin{aligned} P_2(x,y)= f(a,b) & +f_1(a,b)(x-a) +f_2(a,b)(y-b) \\
  & +\frac{1}{2} \left( f_{11}(x-a)^2+f_{22}(y-b)^2+2f_{12}(x-a)(y-b)\right)
  \end{aligned}\\[1ex]
    & \!\begin{aligned} P_2(x,y) & =2+0x+0y+\frac{1}{2}(x-0)^2+\frac{1}{2} \cdot \frac{3}{2}(y-0)^2+\frac{1}{2}\cdot2\cdot0(x-0)(y-0) \\
  & =2+\frac{1}{2}x^2+\frac{3}{4}y^2 \end{aligned}\\
  & P_2(\num{0,1};\num{0,1})=2+\frac{1}{2}(\num{0,1})^2+\frac{3}{4}(\num{0,1})^2=2+\frac{1}{200}+\frac{3}{400}=\frac{805}{400}=\num{2,0125} \\
  & f(\num{0,1};\num{0,1})=\sqrt{2(0,1)^2+3(\num{0,1})^2+4}=\sqrt{\frac{2}{100}+\frac{3}{100}+4}=\sqrt{\frac{405}{100}}=\num{2,01246} \end{align*}

  \section*{Uppgift 2.6}%

  \vskip-\abovedisplayskip
  \begin{align*}
  & f(x,y)=2x+y, \quad g(x,y)=x^2+y^2-5=0 \\
  & L(x,y,\lambda)=f(x,y)+\lambda g(x,y)=2x+y+\lambda (x^2+y^2-5) \\
  & \frac{\partial L}{\partial x}=2+2x\lambda, \quad
  \frac{\partial L}{\partial y}=1+2y\lambda, \quad
  \frac{\partial L}{\partial \lambda}=x^2+y^2-5 \\
  & \text{Söker efter nollställen genom att sätta derivatorna lika med 0} \\
    & \begin{drcases} & \frac{\partial L}{\partial x}= 0=2(1+x\lambda) \Rightarrow \lambda=-\frac{1}{x} \\
  & \frac{\partial L}{\partial y}=0=1+2y\lambda \Rightarrow \lambda =-\frac{1}{2y}
  \end{drcases} \Rightarrow
  -\frac{1}{x}=-\frac{1}{2y} \Rightarrow 2y=x \Rightarrow y=\frac{x}{2} \\
  & \text{Sätter in resultatet i $\frac{\partial L}{\partial \lambda}=0$} \\
  & 0=y^2+x^2-5 \Rightarrow \frac{x^2}{4}+x^2-5=0 \Rightarrow 0=5x^2-20 \Rightarrow
  4=x^2 \Rightarrow x=\pm 2 \\
  & \text{Det ger} \\
  & y=\frac{\pm2}{2}=\pm1 \text{ och } \lambda=\pm \frac{1}{2} \\
  & \text{Ur det får vi punkterna $(2,1)$ och $(-2,-1)$ vilket ger} \\
  & f(2,1)=4+1=5 \quad \text{och} \quad f(-2,-1)=-4-1=-5
\end{align*}

\end{document}

enter image description here

enter image description here

enter image description here

2

(unfortunately, i'm unable to provide a full example, as i'm having problems with the encoding. but since the op is satisfied with his/her output, i'll give the salient details here.)

the split sub-environment, like all sub-environments, is always handled as an unbreakable box. to get rid of that limitation,

  • replace equation* by align*,
  • remove \begin{split} and \end{split}, and
  • insert \allowdisplaybreaks in your preamble.

since you have begun every display line with &, that will keep every line flush left.

you will still have many problems with lines that are wider than the declared text width. check carefully to make sure that nothing is lost by running past the edge of the paper.

possibilities for breaking lines intelligently (and intelligibly) are described in the documentation for amsmath and mathtools.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.