0

EDIT: I tried to add a domain and it still doesn't work.

I'm trying to plot Image of equation with associated graph

I did this with desmos and I assume it's correct since it solves my y(0) = -1 initial condition. When I use

\begin{tikzpicture}
\begin{axis}
    \addplot[]{((4/17)*cos(deg(x))) + ((1/17)*sin(deg(x))) +((-21/17)*e^(-4*x))};
\end{axis}
\end{tikzpicture}

it plots Image created by addplot

I tried to add a domain and range to get a code of

\begin{tikzpicture}
\begin{axis}[
xmin = -0.25, xmax = 6,
ymin = -1.25, ymax = 0.25
]
    \addplot[]{((4/17)*cos(deg(x))) + ((1/17)*sin(deg(x))) +((-21/17)*e^(-4*x))};
\end{axis}
\end{tikzpicture}

but then I just get

New image after adding domain

Clearly the issue is the range but I can't seem to get it to register correctly.

As far as I can tell, I properly typed out the function and yet I'm getting vastly different results. Any help is appreciated, I'm very new to LaTeX so I don't exactly know what I'm doing.

5
  • 5
    You get extremely large (negative) values of the function for x in your domain (note the 10^8 at the top left of the figure). I suggest that you change the domain of your plot to -.25 to 6 or something similar.
    – mickep
    Commented Oct 12, 2023 at 16:25
  • I tried to do that as you said along with a range but it seems like that didn't quite do it either. Now I just have a straight line going from 0? I get a warning that the y-axis is approximately empty so it just expanded it, but like it isn't it's exactly what I need?
    – Motik7
    Commented Oct 12, 2023 at 16:32
  • 3
    What exactly did you do? @mickep meant adding something like domain=-0.25:5 to the axis options. Commented Oct 12, 2023 at 16:51
  • xmin etc only control what is shown, you need to control what is evaluated which needs changing the domain which defaults to the interval [-5:5], which skews your y range as the exponent is very large for x=-5.
    – Dai Bowen
    Commented Oct 12, 2023 at 16:52
  • 3
    Welcome! Please provide compilable code rather than snippets, as it is much easier for people to help effectively.
    – cfr
    Commented Oct 12, 2023 at 17:34

2 Answers 2

4

I tried with tikz only and it works well:

enter image description here

Code:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}
        \filldraw[fill=cyan!10,draw=white] (-1.5,-7) rectangle (9,1.5);% bkd color
        \draw[white](-1,-7) grid (9,1); % grid
        
        %scale on the axis
        \foreach \x in {-1,0,...,8}
            \draw (\x,.1)--(\x,-.1) node[below]() {\footnotesize $\x$};
        \foreach \x in {-6,-5,...,1}
            \draw (.1,\x)--(-.1,\x) node[left]() {\footnotesize $\x$};
        
        % x & y axis
        \draw[->,line width=.5pt] (-1,0)-- (8.5,0) node[below]() {$x$};
        \draw[->,line width=.5pt] (0,-6.5)-- (0,1) node[right]() {$y$};
        
        
        % change data for function(s) to plot in the next lines
        \clip (-1,-6)  rectangle (9,1);
        \draw[smooth,magenta,mark=none,domain=-1:8,line width=2pt] plot (\x,{((4/17)*cos(\x r)) + ((1/17)*sin(\x r)) +((-21/17)*e^(-4*\x))});
        
    \end{tikzpicture}
\end{document}
1
  • 1
    IMO, the important bit is that you've added domain= to the plot, which OP was missing.
    – Teepeemm
    Commented Oct 12, 2023 at 18:11
3

You can try specifying a domain that matches your xmin/xmax parameters (and more points); this seemed to work for me:

\documentclass{minimal}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmin=-0.25,xmax=5,ymin=-1.25,ymax=1.25]
  \addplot[domain=-0.25:5,samples=250]{((4/17)*cos(deg(x))) + ((1/17)*sin(deg(x))) +((-21/17)*e^(-4*x))};
\end{axis}
\end{tikzpicture}
\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .