As you have probably guessed from the title my mother tounge is not English.
Therefore I have no idea if "Functional lines" is the correct term for what I am looking for.
Basically I am looking to make a command similar to the one below
\functionalines{3x}{x-4}{F_x = (3x)(x-4)}
Then the output should be similar to the tikz code below.
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[%
negativ/.style={blue,dashed},
positiv/.style={red},
vertlinje/.style={dotted,opacity=.7},
node distance=1.5ex,
nullpunkt/.style={fill=white,inner sep= 1pt}]
\draw [->,>=stealth] (-5,0) node (linestart) {} -- (5,0) node (lineend) {};
\node (null1) at (-2,0) [label=above:-2] {};
\node (null2) at (1,0) [label=above:1] {};
\node [matrix] (produktledd) [below left=of linestart]{
\node [left] (f1) {$x+2$}; \\
\node [left] (f2) {$x-1$}; \\
\node [left] (f) {$f(x)= x^2+ x - 2$}; \\
};
\draw [vertlinje] (null1) -- (null1 |- f);
\draw [vertlinje] (null2) -- (null2 |- f);
\draw [positiv] (null1 |- f1) -- (lineend |- f1);
\draw [negativ] (f1) -- (null1 |- f1) node[nullpunkt] {$0$};
\draw [negativ] (null1 |- f) -- (null2 |- f);
\draw [positiv] (null2 |- f2) -- (lineend |- f2);
\draw [negativ] (f2) -- (null2 |- f2) node[nullpunkt] {$0$};
\draw [positiv] (f) -- (null1 |- f) node[nullpunkt] {$0$}
(null2 |- f) node[nullpunkt] {$0$} -- (lineend |- f);
\end{tikzpicture}
\end{document}
A very good friend showed me this code =) Although there are a few small edits that would have been nice.
The top vectorline should be lowered a tad, and go over the equations. Above the equations and the vector there should be an x, indicating we are looking at the x-axis.
Preferably there should be a line below the equations, same length as the line above. Images below.
Is this possible to accomplish?
How the code looks
If I could get the output any way I want, I would want it to be like the one below.
So yeah, any idea, how to make a command which gives the desired output?
Best Answer
You could use PGFplots for this. By plotting functions using
all coordinates that do not fulfill the condition will be discarded.
I've defined an environment
functionallines
of the formThe
<zero positions>
argument takes a comma-separated list of x-values where any of the functions are zero or not defined. At these positions, a vertical line will be drawn through the function plots, and the positions will be printed in black at the top of the diagram. If you want to change the labels for these positions, use the<pgfplots arguments>
to supplyextra x tick labels={<first label>,<second label>,...}
.The optional argument can also be used for things like switching off the regular tick labels by setting
xtick=\empty
, or changing the drawing style of the functions by, for example, settingnegative/.style={orange,dashed}, positive/.style={green, ultra thick}
.The
<lower>
and<upper>
arguments define the x-range of the plot.You can then add new lines using
where the optional argument
[<LaTeX math code>]
can be used to specify the code used to print the equation.If the function evaluates to a nonreal value (divide by zero) at one of the zero positions, an
x
is printed instead of a0
.Here are a couple of examples:
Setting the labels for precise zero positions using
extra x ticks labels
, specifying the normal ticks usingxtick={<list>}
to avoid overlaps.And here's the complete code: