Seite 1 von 1

Sinuskurve mit TikZ

Verfasst: Fr 3. Sep 2010, 18:13
von Tina
Hallo,
ich würde gerne eine Sinuskurve mit TikZ erstellen. Ich kann eig mit Tikz relativ gut umgehen und würde daher auch lieber bei TikZ bleiben, anstatt mich noch in gnuplot oder psp reinfuchsen zu müssen.
tikZ hat nur leider ein kleines problem mit dem sinus. Es erstellt mir dabei immer eine Gerade. Ich habe schon alles möglichen kombinationen ausprobiert, und hoffe, ihr könnt mir helfen
\documentclass[12pt]{scrreprt}
\usepackage{ngerman}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amssymb}
\usepackage{tikz}
\usepackage{amsmath}


\begin{document}

\begin{tikzpicture}[domain=0:3.3]
%%Koordinatensysetem
\draw[->](-0.2,0)--(3.5,0)				node[right]{$x$};
\draw[->](0,-1.3)--(0,2.5)						node[above]{$f(x)$};

%%Achsenbeschriftung
\foreach \x in {1,2,3}
	\draw(\x,-1pt)--(\x,1pt) node[below]{\x};h
\foreach \y in {-1,1,2}
	\draw (-1pt,\y)--(1pt,\y) node[left]{\y};
	
\node(0,0)[anchor=north east] {0};

%%Graph
\draw[color=blue]	plot (\x,{sin \x})												node[right]{$f(x)$};

\end{tikzpicture}

\end{document}
Liebe Grüße&danke
tina

Re: Sinuskurve mit TikZ

Verfasst: Fr 3. Sep 2010, 18:43
von bloodworks
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}



\begin{document}

\begin{tikzpicture}[domain=0:14] 
\draw[very thin,color=gray] (-0.1,-1.1) grid (14,3.9);

\draw[->] (-0.2,0) -- (14.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
 \draw[color=blue, samples=150]	plot (\x,{sin(\x r)})	node[right] {$f(x) = \sin x$}; 

\end{tikzpicture}

\end{document}
So gesehen im pgfmaual S. 195. Die Amplitude muss natürlich groß genug sein um einen Ausschlag zu erzeugen und die sampel Größe muss auf einem Werte stehen der Aliasing verhindert und gleichzeitig einen smoothen Eindruck zu Erzeugen. Zu Groß darf er aber nicht sein da das Rechenzeit kostet.
Der Trick ist aber eigentlich das "r" das tut Rad in Deg umwandeln siehe S 413. Das brauchst du nicht beachten wenn du mit Gnuplot arbeitest. Was eig. auch kein Problem ist.

Verfasst: Sa 4. Sep 2010, 14:15
von Tina
danke, für die schnelle hilfe.

ich hab jetzt nur noch ein kleines problem, wenn ich eine etwas komplexere sinusfunktion zeichnen lassen will, da kriegt tikz die phasenverschiebung nicht hin.
\documentclass{scrreprt}
\usepackage[ngerman]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tikz}



\begin{document}

\begin{tikzpicture}[domain=0:3.8]
\draw[step=1, very thin,color=gray] (-0.1,-1.1) grid (3.5,1.2);
%%Koordinatensystem
\draw[->] (-0.2,0) -- (3.8,0) node[right] {$x$};
\draw[->] (0,-1.2) -- (0,1.2) node[above] {$f(x)$};

%%Funktion
\draw[color=blue, samples=150]   plot (\x,{0.5*sin(6*\x r-pi)})   node[right] {$f(x) = \sin x$};

%%x-achse beschriftung
\foreach \x in {1}
   \draw(\x*pi,-1pt)--(\x*pi,1pt) node[below]{\x$ \cdot\pi$};
\foreach \x in {1}
   \draw(\x/2*pi,-1pt)--(\x/2*pi,1pt) node[below]{$\frac{\x}{2}\cdot\pi$};

%%y-achse Beschriftung
\foreach \y in {-1,1}
   \draw (-1pt,\y)--(1pt,\y) node[left]{\y}; 


\end{tikzpicture}

\end{document}
[/b]

Verfasst: Sa 4. Sep 2010, 14:25
von bloodworks
Das gleiche wie zuvor (Minibsp siehe oben).
\begin{tikzpicture}[domain=0:14] 
%%Achsenbeschriftung 
\foreach \x in {1,2,3} 
   \draw(\x,-1pt)--(\x,1pt) node[below]{\x};h 
\foreach \y in {-1,1,2} 
   \draw (-1pt,\y)--(1pt,\y) node[left]{\y}; 
   
\draw[very thin,color=gray] (-0.1,-1.1) grid (14,3.9);

\draw[->] (-0.2,0) -- (14.2,0) node[right] {$x$}; \draw[->] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
 \draw[color=blue, samples=150]	plot (\x,{sin(\x r)})	node[right] {$f(x) = \sin x$}; 
 \draw[color=blue, samples=150] plot (\x,{0.5*sin(6*\x r -{pi r})}) node[right] {$f(x) = 0,5 \sin 6 x -\pi$}; 
  \draw[color=red, samples=150] plot (\x,{0.5*sin(6*\x r -{pi })}) node[right] {$f(x) = 0,5 \sin 6 x $}; 
\end{tikzpicture}