首先,我今天刚开始学习 LaTeX,因为我的教授希望我们从现在开始用它来完成家庭作业。我已附上所有代码,但问题区域在最底部。我正在尝试绘制绝对值\phi (t) - \phi_n (t)
(到目前为止只完成了第一个),但据我所知,没有一个通用包具有内置的绝对值函数,可以真正执行数学运算,而不仅仅是格式化条形图。我是否错过了一些功能或包?
\documentclass[12pt]{article}
\usepackage{fullpage,mathpazo,amsfonts,nicefrac,amsmath,amssymb,enumitem, geometry, pgfplots, physics}
\pgfplotsset{compat = newest}
\geometry{top = 20mm, bottom = 20mm, left = 20mm, right = 20mm}
\begin{document}
\section*{2.8}
\begin{enumerate}[start = 2]
\item Transform the given initial value problem
into an equivalent problem with the initial point at the origin.
\begin{gather*}
\frac{dy}{dt} = 1 - y^3, \quad \quad y(-1) = 3 \\
T = t + 1 \Longrightarrow y(0) = 0 \\
\frac{dy}{dt} = \frac{dy}{dT} * \frac{dT}{dt} = \frac{dy}{dT} \\
\frac{dy}{dT} = 1 - y^3 \\
Y = y-3 \\
\frac{dy}{dT} = 1 - (Y + 3)^3 \\
\frac{dY}{dT} = 1 - (Y + 3)^3, \quad \quad Y(0) = 0 \\
\end{gather*}
\end{enumerate}
\begin{enumerate}[start = 4]
\item Let $\phi _0 (t) = 0$ and define $\{\phi _n (t)\}$ by the method of successive approximations.
\[
y' = -\frac{y}{2} + t, \quad \quad y(0) = 0
\]
\begin{enumerate}
\item Determine $\phi _n (t)$ for an arbitrary value of n.
\begin{gather*}
\int_{0}^{t} \,dy = \int_{0}^{t} -\frac{y}{2} + s \,ds \\
\begin{align*}
\phi (t) &= \int_{0}^{t} -\frac{y}{2} + s \,ds \Longrightarrow \phi_{n+1} (t) = \int_{0}^{t} -\frac{\phi_n}{2} + s \,ds \\
\phi_1 (t) &= \int_{0}^{t} -\frac{y_0}{2} + s \,ds = \frac{t^2}{2} \\
\phi_2 (t) &= \int_{0}^{t} -\frac{s^2}{4} + s \,ds = -\frac{t^3}{12} + \frac{t^2}{2}\\
\phi_3 (t) &= \int_{0}^{t} -\frac{s^3}{24} + \frac{s^2}{4} + s \,ds = \frac{t^4}{96} - \frac{t^3}{12} + \frac{t^2}{2}\\
\phi_4 (t) &= \int_{0}^{t} \frac{s^4}{192} -\frac{s^3}{24} + \frac{s^2}{4} + s \,ds = -\frac{t^5}{960} + \frac{t^4}{96} - \frac{t^3}{12} + \frac{t^2}{2}
\end{align*} \\
\phi_n (t) = 4 \sum_{i=0}^{n} \frac{ (-\frac{t}{2})^i }{ i! } + 2t -4 \\
\end{gather*}
\item Plot $\phi_n (t)$ for $n = 1\ldots4$. Observe whether the iterates appear to be converging.
\begin{tikzpicture}
\begin{axis}[
grid = both,
width = .75 * \textwidth,
height = .5 * \textwidth,
legend pos = north west,
xlabel = t, ylabel = $\phi_n (t)$,
xmin = 0, xmax = 10,
ymin = 0, ymax = 20]
\addplot[domain = 0:10, samples = 100, smooth, thick, blue,] {(x^2)/2};
\addplot[domain = 0:10, samples = 100, smooth, thick, red,] {-x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 100, smooth, thick, green,] {x^4/96 -x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 100, smooth, thick, pink,] {-x^5/960 + x^4/96 -x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 200, smooth, thick, black,] {4*exp(-x/2) + 2*x - 4};
\legend{$\phi_1 (t)$, $\phi_2 (t)$, $\phi_3 (t)$, $\phi_4 (t)$, $\phi (t)$}
\end{axis}
\end{tikzpicture}
\\ The iterates do appear to be converging as $n$ increases.
\item Express $\lim_{n\to\infty} \phi_n (t) = \phi (t)$ in terms of elementary functions; that is, solve the given initial value problem.
\begin{align*}
\lim_{n\to\infty} \phi_n (t) &= \lim_{n\to\infty} 4 \sum_{i=0}^{n} \frac{ (-\frac{t}{2})^i }{ i! } + 2t -4\\
&= 4e^{-\frac{t}{2}} + 2t -4 \\
\phi_n (t) &= 4e^{-\frac{t}{2}} + 2t -4
\end{align*}
\[ \phi (t) = 4e^{-\frac{t}{2}} + 2t -4 , \quad \quad \phi (0) = y (0) = 0 \]
\item Plot $|\phi (t) - \phi_n (t)|$ for each value of $n$. Estimate the interval in which each is a reasonably good approximation to the actual solution. \\
\begin{tikzpicture}
\begin{axis}[
grid = both,
width = .75 * \textwidth,
height = .5 * \textwidth,
legend pos = north west,
xlabel = t, ylabel = $\phi_n (t)$,
xmin = 0, xmax = 10,
ymin = 0, ymax = 10]
\addplot[domain = 0:10, samples = 100, smooth, thick, blue,] {{4*exp(-x/2) + 2*x - 4 - (x^2)/2}};
\addplot[domain = 0:10, samples = 100, smooth, thick, red,] {-x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 100, smooth, thick, green,] {x^4/96 -x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 100, smooth, thick, pink,] {-x^5/960 + x^4/96 -x^3/12 + (x^2)/2};
\addplot[domain = 0:10, samples = 200, smooth, thick, black,] {4*exp(-x/2) + 2*x - 4};
\legend{$\phi_1 (t)$, $\phi_2 (t)$, $\phi_3 (t)$, $\phi_4 (t)$, $\phi (t)$}
\end{axis}
\end{tikzpicture}
\end{enumerate}
\end{enumerate}
\end{document}
答案1
你是这个意思吗?
\addplot[domain = 0:10, samples = 100, smooth, thick, blue,] {{abs((4*exp(-x/2) + 2*x - 4)-(4*exp(-x/2) + 2*x - 4 - (x^2)/2))}};
\addplot[domain = 0:10, samples = 100, smooth, thick, red,] {abs((4*exp(-x/2) + 2*x - 4)-(-x^3/12 + (x^2)/2))};
\addplot[domain = 0:10, samples = 100, smooth, thick, green,] {abs((4*exp(-x/2) + 2*x - 4)-(x^4/96 -x^3/12 + (x^2)/2))};
\addplot[domain = 0:10, samples = 100, smooth, thick, pink,] {abs((4*exp(-x/2) + 2*x - 4)-(x^5/960 + x^4/96 -x^3/12 + (x^2)/2))};
\addplot[domain = 0:10, samples = 200, smooth, thick, black,] {4*exp(-x/2) + 2*x - 4};
\legend{$|\phi (t)-\phi_1 (t)|$, $|\phi (t)-\phi_2 (t)|$, $|\phi (t)-\phi_3 (t)|$, $|\phi (t)-\phi_4 (t)|$, $\phi (t)$}