Math & Sciencepgfplots | Conditions on functions

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
User avatar
cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

pgfplots | Conditions on functions

Post by cgnieder »

I'm not sure I understand... you're not talking about the absolute, are you?

Code: Select all

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
 \begin{axis}[mark=none]
   \addplot[red,samples=200,domain=-2*pi:2*pi]   { (sin(deg(x)))^2 } ;
   \addplot[green,samples=200,domain=-2*pi:2*pi] { sin(deg(x))*(abs(sin(deg(x)))) } ;
 \end{axis}
\end{tikzpicture}

\end{document}
Regards
site moderator & package author

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

Learn LaTeX easily with newest books:

The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis

The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more

LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis

LaTeX Beginner
Posts: 30
Joined: Tue Sep 11, 2012 2:55 pm

pgfplots | Conditions on functions

Post by LaTeX Beginner »

Mmmm, no... I want to take only the positive part of the sin(x) function (sin(x)>0), and operate that with the sin(x) function. In your code, it would be like that (however it doesn't runs):

Code: Select all

\addplot[green,samples=200,domain=-2*pi:2*pi] { sin(deg(x))*(sin(deg(x))>0) } ;
I don't know how to express the condition sin(deg(x))>0... Do you know what I'm saying?
Post Reply