0

All equations fit in a single line, but the 3rd line (equation) is too long, so I need to divided it into 2 lines. I have tried \\ but it doesn't work. This is what I have (I added more space in between so you can see the 3rd equation):

\begin{eqnarray}

&I&= \displaystyle \int_{x_0=0}^{x_2=2h} \left[ \left(\dfrac{x^2-3hx+2h^2}{2h^2}\right)f(x_0) + \left(\dfrac{4hx-2x^2}{2h^2}\right)f(x_1) + \left(\dfrac{x^2-hx}{2h^2}\right)f(x_2)\right] \ dx \nonumber\

&=& \dfrac{1}{2h^2}\left[ \left(\dfrac{x^3}{3}-\dfrac{3hx^2}{2}+2h^2x\right)f(x_0) + \left(\dfrac{4hx^2}{2}-\dfrac{2x^3}{3}\right)f(x_1) + \left(\dfrac{x^3}{3}-\dfrac{hx^2}{2}\right)f(x_2)\right]_0^{2h} \nonumber\

&=& \dfrac{1}{2h^2}\left[ \left(\dfrac{(2h)^3}{3}-\dfrac{3h(2h)^2}{2}+2h^2(2h)\right)f(x_0) + \left(\dfrac{4h(2h)^2}{2}-\dfrac{2(2h)^3}{3}\right)f(x_1) +\left(\dfrac{(2h)^3}{3}-\dfrac{h(2h)^2}{2}\right)f(x_2) + 0\right] \nonumber\

&=&\dfrac{1}{2h^2}\left[ \left(\dfrac{8h^3}{3}-6h^3+4h^3\right)f(x_0) + \left(8h^3-\dfrac{16h^3}{3}\right)f(x_1) + \left(\dfrac{8h^3}{3}-2h^3\right)f(x_2) \right]\nonumber \

&=&\dfrac{1}{2h^2}\left[ \left(\dfrac{2h^3}{3}\right)f(x_0) + \left(\dfrac{8h^3}{3}\right)f(x_1) + \left(\dfrac{2h^3}{3}\right)f(x_2) \right] \nonumber\

&=&\dfrac{1}{2h^2}\cdot \dfrac{2h^3}{3}\left[ f(x_0) + 4f(x_1) + f(x_2) \right] \nonumber\ &=&\dfrac{h}{3}\left[ f(x_0) + 4f(x_1) + f(x_2) \right] \ \end{eqnarray}

Skillmon
  • 60,462
Anna
  • 3
  • 1
    You shouldn't use eqnarray, it often gives inconsistent spacing. Instead, you should use align from amsmath. – Skillmon Dec 04 '20 at 15:57
  • @Skillmon Thanks! That worked but "program@e..." appeared just at the end of the 3rd equation, and don't know how to remove it. – Anna Dec 04 '20 at 16:12
  • Off topic: Blank lines aren't allowed in math; this should have resulted in error messages on that account. – barbara beeton Dec 04 '20 at 16:23

1 Answers1

1

Never ever use eqnarray. In this case, equation and split are the best.

\documentclass{article}
\usepackage{geometry} % more generous text width
\usepackage{amsmath}

\begin{document}

\begin{equation} \begin{split} I&= \int_{x_0=0}^{x_2=2h} \left[ \left(\frac{x^2-3hx+2h^2}{2h^2}\right)f(x_0) + \left(\frac{4hx-2x^2}{2h^2}\right)f(x_1) + \left(\frac{x^2-hx}{2h^2}\right)f(x_2) \right] , dx \[1ex] &= \frac{1}{2h^2}\left[ \left(\frac{x^3}{3}-\frac{3hx^2}{2}+2h^2x\right)f(x_0) + \left(\frac{4hx^2}{2}-\frac{2x^3}{3}\right)f(x_1) + \left(\frac{x^3}{3}-\frac{hx^2}{2}\right)f(x_2) \right]_0^{2h} \[1ex] &= \frac{1}{2h^2}\biggl[ \begin{aligned}[t] & \left(\frac{(2h)^3}{3}-\frac{3h(2h)^2}{2}+2h^2(2h)\right)f(x_0) + \left(\frac{4h(2h)^2}{2}-\frac{2(2h)^3}{3}\right)f(x_1) \ &+ \left(\frac{(2h)^3}{3}-\frac{h(2h)^2}{2}\right)f(x_2) + 0 \biggr] \end{aligned} \[1ex] &=\frac{1}{2h^2}\left[ \left(\frac{8h^3}{3}-6h^3+4h^3\right)f(x_0) + \left(8h^3-\frac{16h^3}{3}\right)f(x_1) + \left(\frac{8h^3}{3}-2h^3\right)f(x_2) \right] \[1ex] &=\frac{1}{2h^2}\left[ \left(\frac{2h^3}{3}\right)f(x_0) + \left(\frac{8h^3}{3}\right)f(x_1) + \left(\frac{2h^3}{3}\right)f(x_2) \right] \[1ex] &=\frac{1}{2h^2}\cdot \frac{2h^3}{3}\left[ f(x_0) + 4f(x_1) + f(x_2) \right] \[1ex] &=\frac{h}{3}\left[ f(x_0) + 4f(x_1) + f(x_2) \right] \end{split} \end{equation}

\end{document}

enter image description here

I'd consider also splitting the computations (if at all necessary, as they're quite elementary):

\documentclass{article}
\usepackage{geometry} % more generous text width
\usepackage{amsmath}

\begin{document}

\begin{equation} \begin{split} I&= \int_{x_0=0}^{x_2=2h} \left[ \left(\frac{x^2-3hx+2h^2}{2h^2}\right)f(x_0) + \left(\frac{4hx-2x^2}{2h^2}\right)f(x_1) + \left(\frac{x^2-hx}{2h^2}\right)f(x_2) \right] , dx \ &= \frac{1}{2h^2}\bigl[f(x_0)I_0 + f(x_1)I_1 + f(x_2)I_2\bigr] \[2ex] I_0 &= \left[\frac{x^3}{3}-\frac{3hx^2}{2}+2h^2x\right]_0^{2h} = \left(\frac{(2h)^3}{3}-\frac{3h(2h)^2}{2}+2h^2(2h)\right) \ &= \left(\frac{8h^3}{3}-6h^3+4h^3\right) = \frac{2h^3}{3} \[1ex] I_1 &= \left[\frac{4hx^2}{2}-\frac{2x^3}{3}\right]_0^{2h} = \left(\frac{4h(2h)^2}{2}-\frac{2(2h)^3}{3}\right) \ &= \left(8h^3-\frac{16h^3}{3}\right) = \frac{8h^3}{3} \[1ex] I_2 &= \left[\frac{x^3}{3}-\frac{hx^2}{2}\right]_0^{2h} = \left(\frac{(2h)^3}{3}-\frac{h(2h)^2}{2}\right) \ &= \left(\frac{8h^3}{3}-2h^3\right) = \frac{2h^3}{3} \[2ex] I &= \frac{h}{3}[f(x_0) + 4f(x_1) + f(x_2)] \end{split} \end{equation}

\end{document}

enter image description here

egreg
  • 1,121,712
  • Uhm, given the amount of whitespace introduced by \right] this is one of the few situations where I wouldn't necessarily put \, before the differential. – campa Dec 04 '20 at 17:05
  • @campa That's the least part… ;-) – egreg Dec 04 '20 at 17:19