4

I want typing math equation like this: enter image description here But with this code I can't get the result like above. Anyone can help me to edit my code to get the above result?

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{align}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\nonumber\\
    %%%%%%%%%%%%%%%%%%%%%%
    &-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\nonumber\\
    \begin{aligned}
    &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)
    -\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    \end{aligned}
    \end{align}
\end{document}

1 Answer 1

6

For the equation number centered, use equation and aligned, rather than align. For the indents, I inserted \qquad where needed. I also had to break up one of your long lines to make room for the centered eqn number.

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{equation}
\begin{aligned}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\\
  &\qquad+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\\
    %%%%%%%%%%%%%%%%%%%%%%
    &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\\
    &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)\\
   &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    \end{aligned}
\end{equation}
\end{document}

enter image description here


ADDENDUM

The OP's comment offered a different interpretation of what is desired. Hopefully, this matches the desire.

\documentclass{book}
\usepackage{amsmath}
\begin{document}
\begin{align}
    u_j^{n+1}&=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +\dfrac{(\Delta t)^2}{2}\left(a(t_n)^2\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{\partial u}{\partial x}\right)\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \dfrac{\partial u}{\partial x}
    +a(t_n)^2\dfrac{(\Delta t)^2}{2}\dfrac{\partial^2 u}{\partial x^2}-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\dfrac{\partial u}{\partial x}\nonumber\\
    &=u_j^{n}-a(t_n)\Delta t \left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)
  \nonumber\\
  &\qquad+a(t_n)^2\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}}{(\Delta x)^2}\right)\nonumber\\
    %%%%%%%%%%%%%%%%%%%%%%
    &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{2}\left(\dfrac{u_{j+1}^{n}-u_{j-1}^{n}}{2\Delta x}\right)\nonumber\\
    & 
\begin{aligned}
{} &= u_j^{n}-\dfrac{1}{2}\nu_n\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
    +\dfrac{1}{2}\nu_n^2 \left(u_{j+1}^{n}-2u_{j}^{n}+u_{j-1}^{n}\right)\\ 
  &\qquad-\dfrac{da(t_n)}{dt}\dfrac{(\Delta t)^2}{4\Delta x}\left(u_{j+1}^{n}-u_{j-1}^{n}\right)
\end{aligned}
    \end{align}
\end{document}

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .