Seite 1 von 1

Funktionen zeichnen

Verfasst: Mo 2. Dez 2019, 13:54
von Eduard
Hallo zusammen,

ich würde gerne die angehängt Funktion zeichnen. Leider kenne ich mich tikzpicture gar nicht aus. Habe folgendes gefunden, weiß aber nicht, wie ich das Ganze so verändern kann, damit meine gewünschte Funktion rauskommt.
\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[
    scale=5,
    axis/.style={very thick, ->, >=stealth'},
    important line/.style={thick},
    dashed line/.style={dashed, thin},
    pile/.style={thick, ->, >=stealth', shorten <=2pt, shorten
    >=2pt},
    every node/.style={color=black}
    ]
    % axis
    \draw[axis] (-0.1,0)  -- (1.1,0) node(xline)[right]
        {$x_2$};
    \draw[axis] (0,-0.1) -- (0,1.1) node(yline)[above] {$x_1$};
    % Lines
    \draw[important line] (.15,.15) coordinate (A) -- (.85,.85)
        coordinate (B) node[right, text width=5em] {$Y^O$};
    \draw[important line] (.0,.85) coordinate (C) -- (.85,.15)
        coordinate (D) node[right, text width=7em] {$\mathit{NX}=x$};
    % Intersection of lines
    \fill[red] (intersection cs:
       first line={(A) -- (B)},
       second line={(C) -- (D)}) coordinate (E) circle (.4pt)
       node[above,] {$A$};
    % The E point is placed more or less randomly
    \fill[red]  (E) +(-.075cm,-.2cm) coordinate (out) circle (.4pt)
        node[below left] {$B$};
    % Line connecting out and ext balances
    \draw [pile] (out) -- (intersection of A--B and out--[shift={(0:1pt)}]out)
        coordinate (extbal);
    \fill[red] (extbal) circle (.4pt) node[above] {$C$};
    % line connecting  out and int balances
    \draw [pile] (out) -- (intersection of C--D and out--[shift={(0:1pt)}]out)
        coordinate (intbal);
    \fill[red] (intbal) circle (.4pt) node[above] {$D$};
    % line between out og all balanced out :)
    \draw[pile] (out) -- (E);
\end{tikzpicture}
\end{document}
Wäre super, falls mir jemand kurz sagen könnte, wie ich das hinbekommen. Vielen Dank!

Verfasst: Mo 2. Dez 2019, 15:00
von markusv
Hallo.

Eine Möglichkeit, welche sich aber sicherlich noch eleganter gestalten lässt:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{mathtools}
\begin{document}
\begin{tikzpicture}[scale=3]
    % axis
    \draw[thin,-latex] (0,0)  -- (1.5,0) node(xline)[below] {$x_1$};
    \draw[thin,-latex] (0,0) -- (0,1.5) node(yline)[left] {$x_2$};
    % Lines
    \draw[] (0,1) node[left] {$\dfrac{y}{p_2}$} -- (1,0) node[below] {$\dfrac{y}{p_1}$};
    \draw[dashed] (0,.5) node[left] {$x_2^*$} -| (.5,0) node[below] {$x_1^*$};
    \draw[fill] (.5,.5) circle (.5pt) node[xshift=.75cm] {$-\dfrac{p_1}{p_2}$};
    \draw (0.5,0.5) arc(45:90:-1);
    \draw (0.5,0.5) arc(45:0:-1);
\end{tikzpicture}
\end{document}

Verfasst: Mo 2. Dez 2019, 15:10
von Eduard
Super! Das sieht perfekt aus! Gibt es irgendwo eine Anleitung (Schritt für Schritt) wie man solche Sachen zeichnen kann? Ich verstehe nämlich noch nicht ganz wie das funktioniert, um selbst so etwas zusammenzustellen.

Aus erster Hand

Verfasst: Mo 2. Dez 2019, 17:11
von Stamm-
Eduard hat geschrieben:[…] Gibt es irgendwo eine Anleitung (Schritt für Schritt) wie man solche Sachen zeichnen kann? Ich verstehe nämlich noch nicht ganz wie das funktioniert, um selbst so etwas zusammenzustellen.
Klar. Die Anleitung zu »PGF/TikZ« (1302 Seiten). Teil I davon ist für Anfänger sicher ganz besonders interessant. Kommandozeile öffnen und hiermit die Anleitung mit »texdoc« abrufen.
  • texdoc pgf

Verfasst: Mo 2. Dez 2019, 17:17
von Eduard
ich habe jetzt versucht eine fallende Gerade zu zeichnen:
\begin{tikzpicture} 
\hspace*{1cm}
\draw [->] (0,0) -- (4,0) node[right] {$\textcolor{brown}{\pmb{x_1}}$};
\draw [->] (0,0) -- (0,4) node[above] {$\textcolor{magenta}{\pmb{x_2}}$;

%\draw[orange, domain=0:4]  plot (\x, {-x+3.5});
\draw [orange, very thick] (0,3.5) -- (3.5,0);

\end{tikzpicture}
Mit der Funktion draw geht das. Aber mit Plot nicht. Wie genau müsste ich so eine Funktion eingeben? Also Beispiel: y=3.5x

Die meisten Beispiele verwenden eine e-Funktion oder sin oder cos.

Verfasst: Mo 2. Dez 2019, 17:39
von Bartman
\documentclass[tikz]{standalone}
\newcommand{\pmb}{}% unbekannter Befehl

\begin{document}
\begin{tikzpicture}
\draw [->] (0,0) -- (4,0) node[right, text=brown] {$\pmb{x_1}$};
\draw [->] (0,0) -- (0,4) node[above, text=magenta] {$\pmb{x_2}$};% Der mathematische Modus endet bei Dir an der falschen Stelle.

\draw[orange, domain=0:4]  plot (\x, {-\x+3.5});% Beim zweiten x fehlt der Backslash.
\draw [orange, very thick] (0,3.5) -- (3.5,0);
\end{tikzpicture}
\end{document}

Verfasst: Mo 2. Dez 2019, 17:43
von Eduard
Perfekt! In der Zwischenzeit habe ich schon das Manual angefangen zu lesen. Langsam wird einiges klar, aber insgesamt wirkt es trotzdem noch hoch komplex. Vielen Dank für deine Hilfe!

Detailfrage

Verfasst: Mo 2. Dez 2019, 17:44
von Stamm-
\documentclass[parskip=half]{scrartcl}
\usepackage[T1]{fontenc}

\PassOptionsToPackage{svgnames}{xcolor}
\usepackage{tikz}
\usepackage{bm}

\usepackage{lmodern}
\usepackage{microtype}

\begin{document}
  \begin{tikzpicture}[domain=0:4]
    \draw [->] (0,0) -- (4,0) node[right] {$\textcolor{brown}{\bm{x_1}}$};
    \draw [->] (0,0) -- (0,4) node[above] {$\textcolor{magenta}{\bm{x_2}}$};
    \draw[orange] plot (\x,{-\x+3.5});
  \end{tikzpicture}
\end{document}