1

please i need help, i have a problem with i-2

i work on this: http://texwelt.de/wissen/fragen/4912/skizze-zur-illustration-linearer-regression

and i'm trying to do something like this enter image description here

\documentclass[12pt,oneside,fleqn]{book}
\usepackage{tikz}
\usetikzlibrary{arrows,intersections}
\tikzpicture[
thick,
>=stealth',
dot/.style = {
draw,
fill=white,
circle,
inner sep=1pt,
minimum size=7pt
}
]
\coordinate (O) at (0,0);
\draw[->] (-0.3,0) -- (8,0) coordinate[label={below:$t$}] (xmax);
\draw[->] (0,-0.3) -- (0,7) coordinate[label={right:$y$}] (ymax);
\path[name path=x] (0,0) -- (7,7);
\path[name path=y] plot[smooth] coordinates {(-0.3,2) (2,1.5) (4,2.8) (6,5)};
\scope[name intersections={of=x and y,name=i}]
\draw (0,0) -- (5,5) node[pos=1,below right] {f(t)=t};
\draw (i-1) node[dot](i-1) {} -- node[left] {} (i-1 |- O) node[dot,label={below:$(r-1)!$}] {};
\path (i-2) node[dot,label={above:$Q$}] (i-2) {} -- (i-2 |- i-1) node[dot] (i-12) {};
% \draw (i-2) -- (i-2 |- O) node[dot,label={below:$x_0 + \varepsilon$}] {};
%\draw[blue,<->] (i-2) -- node[right] {$f(x_0 + \varepsilon) - f(x_0)$} (i-12);
%\draw[blue,<->] (i-1) -- node[below] {$\varepsilon$} (i-12);
%\path (i-1 |- O) -- node[below] {$\varepsilon$} (i-2 |- O);
%\draw[gray] (i-2) -- (i-2 -| xmax);
%\draw[gray,<->] ([xshift=-0.5cm]i-2 -| xmax) -- node[fill=white] {$f(x_0 + \varepsilon)$} ([xshift=-0.5cm]xmax);
\end{scope}
\end{tikzpicture}
  • 1
    Please always post complete code which people can compile. This is much more useful than mere fragments. – cfr Aug 26 '16 at 23:10
  • What is the question? – luchonacho Aug 27 '16 at 7:53
  • @luchonacho i want to modify the code to obtain the same thing as the picture – Vrouvrou Aug 27 '16 at 7:56
  • 1
    Crosspost – Johannes_B Aug 27 '16 at 19:09
2

I already answered in the LaTeX Community forum, but copy the code here too. It relies on the simple function f(t)=t that makes calculation of intersections not really necessary.

  • draw the axes
  • draw all points and connections in a \foreach loop
  • add nodes for labels using the quotes library syntax
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{arrows,quotes}
\begin{document}
\begin{tikzpicture}[
    thick,
    >=stealth',
     empty dot/.style = { circle, draw, fill = white!0,
                          inner sep = 0pt, minimum size = 4pt },
    filled dot/.style = { empty dot, fill = black}
  ]
  \def\r{3}
  \draw[->] (-0.5,0) -- (6,0) coordinate[label = {below:$t$}] (xmax);
  \draw[->] (0,-0.5) -- (0,6) coordinate[label = {left:$y$}]  (ymax);
  \draw [dashed] (0,0) -- (5,5);
  \foreach \i in {\r+1,\r,\r-1} {
    \draw [densely dashed] (\i,\i)   -- (\i+1,\i);
    \draw [densely dashed] (\i,\i)   -- (\i,0);
    \draw [densely dashed] (\i+1,\i) -- (\i+1,0);
    \node [filled dot] at (\i,\i) {};
    \node [empty  dot] at (\i+1,\i) {};
  }
  \node ["above right:$f(t)=t$"]  at (5,5) {};
  \node ["above right:$\phi(t)$"] at (\r+2,\r+1) {};
  \node ["below:$(r-1)!$"] at (\r-1,0) {};
  \node ["below:$\phantom{()}r!$"]     at (\r,0)   {};
  \node ["below:$(r+1)!$"] at (\r+1,0) {};
\end{tikzpicture}
\end{document}

Output

Link to LC question: Graph with TikZ.

4

So the coordinate (i-2) will be the second intersection of the paths named x and y. The code you have for the paths produces two plots which intersect just once, so no (i-2) is defined, see below (x in red and y in blue).

enter image description here

Replacing the last coordinate with something which creates a second coordinate (using (4.5,7) in this case) and uncommenting some of your later code demonstrates the (i-2) coordinate working.

enter image description here

Finally a couple of tweaks to make the rest of the code compile and I think this is the desired result

enter image description here

Which was produced with the following code

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{arrows,intersections}

\begin{document}

\tikzpicture[
thick,
>=stealth',
dot/.style = {
draw,
fill=white,
circle,
inner sep=1pt,
minimum size=7pt
}
]
\coordinate (O) at (0,0);
\draw[->] (-0.3,0) -- (8,0) coordinate[label={below:$t$}] (xmax);
\draw[->] (0,-0.3) -- (0,7) coordinate[label={right:$y$}] (ymax);
\path[name path=x] (0,0) -- (7,7);
\path[name path=y] plot [smooth] coordinates {(-0.3,2) (2,1.5) (4,2.8) (4.5,7)};
\scope[name intersections={of=x and y,name=i}]
\draw (0,0) -- (5,5) node[pos=1,below right] {f(t)=t};
\draw (i-1) node[dot](i-1) {} -- node[left] {} (i-1 |- O) node[dot,label={below:$(r-1)!$}] {};
\draw (i-2) node[dot,label={above:$Q$}] {} -- (i-2) -- (i-2 |- i-1) node[dot,label={}] (i-12) {};
\draw (i-2) -- (i-2 |- O) node[dot,label={below:$x_0 + \varepsilon$}] {};
\draw[blue,<->] (i-2) -- (i-12) node[right] {$f(x_0 + \varepsilon) - f(x_0)$};
\draw[blue,<->] (i-1) -- (i-12) node[below] {$\varepsilon$};
\path (i-1 |- O) -- node[below] {$\varepsilon$} (i-2 |- O);
\draw[gray] (i-2) -- (i-2 -| xmax);
\draw[gray,<->] ([xshift=-0.5cm]i-2 -| xmax) -- node[fill=white] {$f(x_0 + \varepsilon)$} ([xshift=-0.5cm]xmax);
\endscope
\endtikzpicture

\end{document}
  • How to do to makes 3 points of intersection please – Vrouvrou Aug 27 '16 at 7:09
  • i want to do 3 point (r-1)!, r!, (r+1)! like in the picture how to do please – Vrouvrou Aug 27 '16 at 7:34
  • @Vrouvrou Try to understand the code by reading in the TikZ manual. Then add the third point in a similar way. – Stefan Kottwitz Aug 27 '16 at 16:26
  • i need this graph for tomorrow so i can't read all the manual now, if you know how to do to make points like in the picture please tel me that – Vrouvrou Aug 27 '16 at 16:32
  • 1
    @Vrouvrou Modifying that working code requires reading a bit in the manual but not reading all of it. If you don't want to learn and just want the work to be done for you, TeX consultants can help you: tug.org/consultants.html – Stefan Kottwitz Aug 27 '16 at 17:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.