
Beim Zeichnen des Graphen aus meinemletzte FrageIch habe festgestellt, dass die Diagramme, die ich von PGFplots erhalte, nicht ganz korrekt sind. Ich habe versucht, Diagramme (4.9/(w^2))*(cosh(w*x)-cos(w*x))
für mehrere Werte von zu erstellen w
. Mit Hilfe der Benutzer 1010011010 und Enthusiastic Student konnte ich gut aussehende Diagramme erstellen – zumindest bis ich überprüfte, was ich mit WolframAlpha erhalten sollte.
Da w
in meiner obigen Formel zu geht 0
, sollte die Funktion 4.9*x^2
von oben asymptotisch zu gehen. Das ist nicht das, was die Daten zeigen. Mit diesem Code, der im obigen Link im Wesentlichen nur 1010011010 ist,
\documentclass{standalone}
\usepackage{pgfplots}
\def\mycolone{yellow}
\def\mycoltwo{green}
\pgfplotsset{every axis legend/.append style={at={(.5,-.2)}, anchor=north}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-10,xmax=10,ymin=-0.5,ymax=100,no markers, grid=both, samples=100, restrict y to domain=0:1000]
\foreach \w in {5,10,...,100} {\edef\tmp{\noexpand\addplot[\mycolone!\w!\mycoltwo, domain=-10:10]}
\pgfmathparse{\w/100}
\edef\x{\pgfmathresult}
\tmp{(4.9/((\w/100)^2))*(cosh(\w*x/100)-cos(\w*x/100))};
\edef\legendentry{\noexpand\addlegendentry{$\omega = \noexpand\pgfmathprintnumber[fixed,fixed zerofill, precision=2]{\x}$}};
\legendentry}
\addplot[draw=red, domain=-10:10] {4.9*x^2};
\end{axis}
\end{tikzpicture}
\end{document}
Ich erhalte die folgenden Diagramme.
Hier ist das rote Diagramm
(4.9)*x^2
.
Als Referenz ist hier, was WolframAlpha mir für die höchsten und niedrigsten Werte von w
oben aufgetragen ( w=0.05
und w=1
) und die Darstellung von gibt (4.9)*x^2
:
Es ist schwer zu sagen, aber wenn ich die 4.9*x^2
Handlung entferne, können Sie sehen, dass die Handlung w=0.05
ihr ziemlich genau folgt.
Dies ist ein ganz anderes Verhalten als das erste Bild oben. Meine Frage ist also, wie PGFplots Dinge wie exp
, cosh
, und berechnet cos
und wie ich in Zukunft eine bessere Annäherung erreichen kann?
Antwort1
Die trigonometrischen Funktionen von pgf
nehmen Eingaben in Grad an. Um einen Winkel in Radiant einzugeben, verwenden Sie den speziellen r
Operator: Ersetzen Sie cos(\w*x/100)
durch cos(\w*x/100 r)
.
\documentclass{standalone}
\usepackage{pgfplots}
\def\mycolone{yellow}
\def\mycoltwo{green}
\pgfplotsset{compat=1.12,every axis legend/.append style={at={(.5,-.2)}, anchor=north}}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-10,xmax=10,ymin=-0.5,ymax=100,no markers, grid=both, samples=100, restrict y to domain=0:1000]
\foreach \w in {5,10,...,100} {\edef\tmp{\noexpand\addplot[\mycolone!\w!\mycoltwo, domain=-10:10]}
\pgfmathparse{\w/100}
\edef\x{\pgfmathresult}
\tmp{(4.9/((\w/100)^2))*(cosh(\w*x/100)-cos(\w*x/100 r))};
\edef\legendentry{\noexpand\addlegendentry{$\omega = \noexpand\pgfmathprintnumber[fixed,fixed zerofill, precision=2]{\x}$}};
\legendentry}
\addplot[draw=red, domain=-10:10] {4.9*x^2};
\end{axis}
\end{tikzpicture}
\end{document}
Alternativ können wir mit pgfplots
v1.11 oder neuer mit einem neuen Schlüssel trig format plots
das Winkelformat für alle \addplot
Befehle im Bereich der Schlüsseleinstellung 1 ändern . Hier verwende ich auf der obersten Ebene, um das Verhalten für das gesamte Dokument zu ändern, aber es könnte auch pro Achse oder pro Plot angewendet werden. Beachten Sie, dass dies nur ' -Befehle trig format plots=rad
betrifft , nicht einfache Tipgfplots
\addplot
kZ-Code mit trigonometrischen Funktionen. Darüber hinaus ist dieser Schlüssel etwas experimentell und funktioniert möglicherweise nicht richtig mit exotischeren Achsentypen wie polar
und smithchart
. Im Pakethandbuch wird erwähnt, dass er nur für Standardachsen getestet wurde.
\documentclass{standalone}
\usepackage{pgfplots}
\def\mycolone{yellow}
\def\mycoltwo{green}
\pgfplotsset{
compat=1.12,
every axis legend/.append style={at={(.5,-.2)}, anchor=north},
trig format plots=rad,
}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-10,xmax=10,ymin=-0.5,ymax=100,no markers, grid=both, samples=100, restrict y to domain=0:1000]
\foreach \w in {5,10,...,100} {\edef\tmp{\noexpand\addplot[\mycolone!\w!\mycoltwo, domain=-10:10]}
\pgfmathparse{\w/100}
\edef\x{\pgfmathresult}
\tmp{(4.9/((\w/100)^2))*(cosh(\w*x/100)-cos(\w*x/100))};
\edef\legendentry{\noexpand\addlegendentry{$\omega = \noexpand\pgfmathprintnumber[fixed,fixed zerofill, precision=2]{\x}$}};
\legendentry}
\addplot[draw=red, domain=-10:10] {4.9*x^2};
\end{axis}
\end{tikzpicture}
\end{document}
Beide Methoden führen zum richtigen Ergebnis:
1 Dank anChristian Feuersänger, dem pgfplots
Autor selbst, dafür, dass er mich in einem Kommentar auf diese neue Methode aufmerksam gemacht hat.