1

I would like to find the maximum of a curve and show the value as I have indicated in the picure below. I can't find any example in this forum that is applicable to my case.

\documentclass[border=5pt]{standalone}

\usepackage{tikz} \usepackage{pgfplots} \pgfplotsset{compat=newest} \usepgfplotslibrary{units}

\begin{document}

\begin{tikzpicture} \begin{axis}[change y base, x unit= , % y SI prefix=kilo, y unit= , xmin=0, xmax=1, ymin=0, ymax=1.1, % ytick={0,1000,...,6000}, xlabel=Degree, ylabel=Force, xlabel={$S_r$}, ylabel={$F_x/F_z$}, xlabel style={below right}, ylabel style={above left}, height=8cm, width=9cm, grid=minor, samples=99, trig format plots=rad ]

\newcommand\SV{80.1} \newcommand\SH{0} \newcommand\B{0.210} \newcommand\C{1.67} \newcommand\D{6090} \newcommand\E{0.686} \newcommand\Fz{6000}

\addplot[domain=0:1, blue, thick] {(\SV+\Dsin(\Catan(\B(1-\E)(x100+\SH) +( atan(\B(x*100+\SH)) )
) ) )/\Fz }; \addlegendentry{$F_x(F_z=6kN)$} \end{axis}

\end{tikzpicture}

\end{document}

enter image description here

John W. de Burgh
  • 1,245
  • 1
  • 7
  • 15
  • Hm, if you recall Analysis it's not a simple problem with many possible outcomes ranging from none to many, depending on ranges etc. ... What's the background or purpose of your question? Why don't you calculate at least the first derivative on paper, which is not too hard to do for your function? – MS-SPO Sep 28 '21 at 13:15
  • A good pocket calculator could do it as well. – John Kormylo Sep 28 '21 at 14:10
  • I could surely do calculate the derivative. I already have, but I am sure that there must be a way just to take the highest value (of the 99 points of the curve) and get the corresponding x value. – John W. de Burgh Sep 28 '21 at 15:13
  • Is your update the solution to your problem? If yes, you may want to post it as an answer to your own question and accept it. – Jasper Habicht Sep 28 '21 at 19:39
  • @JohnW.deBurgh It is probably more appropriate to post your "update" as an answer. It is ok to self-answer questions (and accept the answer). – gernot Sep 28 '21 at 19:39

1 Answers1

0

With the help from this post I have now been able to plot what I wanted (without doing the derivative).

\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\usepgfplotslibrary{units}

\makeatletter \pgfplotsset{ /tikz/max node/.style={ anchor=south, }, /tikz/min node/.style={ anchor=north, name=minimum }, mark min/.style={ point meta rel=per plot, visualization depends on={x \as \xvalue}, scatter/@pre marker code/.code={% \ifx\pgfplotspointmeta\pgfplots@metamin \def\markopts{}% \coordinate (minimum); \node [min node] { \pgfmathprintnumber[fixed]{\xvalue},% \pgfmathprintnumber[fixed]{\pgfplotspointmeta} }; \else \def\markopts{mark=none} \fi \expandafter\scope\expandafter[\markopts,every node near coord/.style=green] },% scatter/@post marker code/.code={% \endscope }, scatter, }, mark max/.style={ point meta rel=per plot, visualization depends on={x \as \xvalue}, scatter/@pre marker code/.code={% \ifx\pgfplotspointmeta\pgfplots@metamax \def\markopts{}% \coordinate (maximum); \node [max node] { \pgfmathprintnumber[fixed]{\xvalue},% \pgfmathprintnumber[fixed]{\pgfplotspointmeta} }; \else \def\markopts{mark=none} \fi \expandafter\scope\expandafter[\markopts] },% scatter/@post marker code/.code={% \endscope }, scatter } } \makeatother

\begin{document}

\begin{tikzpicture} \begin{axis}[change y base, x unit= , % y SI prefix=kilo, y unit= , xmin=0, xmax=1, ymin=0, ymax=1.1, % ytick={0,1000,...,6000}, xlabel=Degree, ylabel=Force, xlabel={$S_r$}, ylabel={$F_x/F_z$}, xlabel style={below right}, ylabel style={above left}, height=8cm, width=9cm, grid=minor, samples=199, trig format plots=rad, domain=0:1, blue, axis lines*=middle,after end axis/.code={ \draw [thick, dashed, gray] (maximum) --({axis cs:0,0}-|maximum);} ]

\newcommand\SV{80.1} \newcommand\SH{0} \newcommand\B{0.210} \newcommand\C{1.67} \newcommand\D{6090} \newcommand\E{0.686} \newcommand\Fz{6000}

\addplot +[mark max] plot {(\SV+\Dsin(\Catan(\B(1-\E)(x100+\SH) +( atan(\B(x*100+\SH)) )
) ) )/\Fz }; \addlegendentry{$F_x(F_z=6kN)$} \end{axis}

\end{tikzpicture}

\end{document}

enter image description here

John W. de Burgh
  • 1,245
  • 1
  • 7
  • 15