7

The function I am trying to plot is y = \frac{6x^2-3x+4}{2x^2-8}

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{titling}
\usepackage{amssymb}
\usepackage{pgfplots}

\begin{tikzpicture}
    \begin{axis}
        [
        title = Graph of $\frac{6x^2-3x+4}{2x^2-8}$,
        axis lines = center,
        xlabel = $x$,
        ylabel = $y$,
        ]
        \addplot[color=red]{y = \frac{6x^2-3x+4}{2x^2-8}};
    \end{axis}
\end{tikzpicture}

I am new to LaTex and I've been trying to follow other answers on here, but I'm still a bit confused. Apologies for posting a duplicate.

Edit: Sorry if I wasn't clear, here is how it's supposed to look.

  • 1
    Hello and welcome! Try replacing y=\frac{6x^2-3x+4}{2x^2-8} with (6*x^2-3*x+4)(2*x^2-8) as a starting point – cmhughes Oct 6 '19 at 18:42
  • In addition, use unbounded coords=jump, to make the plot jump at the poles. – Schrödinger's cat Oct 6 '19 at 19:07
10

You can try the following, if you want a smoother plot, just increase the number of points.

\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}

\begin{document}

\begin{tikzpicture}
    \begin{axis}
        [
        title = Graph of $\frac{6x^2-3x+4}{2x^2-8}$,
        axis lines = center,
        xlabel = $x$,
        ylabel = $y$,
        ]
        \addplot[color=red]{ (6*x^2-3*x+4) / (2*x^2-8) };
    \end{axis}
\end{tikzpicture}

\end{document}

enter image description here

Edit:

As I said, you can increase no. points by samples=<..> and also you can limit ymin and ymax because you have two infinite discontinuities at {±2}:

\begin{tikzpicture}
    \begin{axis}
        [
        title = Graph of $\frac{6x^2-3x+4}{2x^2-8}$,
        axis lines = center,
        xlabel = $x$,
        ylabel = $y$,
        samples=500,
        ymin=-150, ymax=150,
        ]
        \addplot[color=red]{ (6*x^2-3*x+4) / (2*x^2-8) };
    \end{axis}
\end{tikzpicture}

enter image description here

  • That's not how the graph should look. Here is how it should look, sorry if I wasn't clear! link to the graph – maxgonz Oct 6 '19 at 18:52
  • That is exactly how the graph in the provided link looks like, besides that it isn't really smooth, because by default "only" 25 sample points are used. That is why AboAmmar suggested to increase samples to a higher number. – Stefan Pinnow Oct 6 '19 at 18:57
  • @StefanPinnow Oh sorry, thank you! – maxgonz Oct 6 '19 at 19:00
  • Except it's not really what the graph looks like. The way this was implemented has led to near-vertical red lines around the singularities, which appears to be part of the graph when it shouldn't. – YiFan Oct 7 '19 at 5:17
  • The graph you drawn has no asymptote, so it can’t be an exact answer – Black Mild Oct 7 '19 at 12:27
6

with plain TikZ:

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}[yscale=1/30,xscale=1.2,
declare function={
f(\x)=(6*\x*\x-3*\x+4)/(2*\x*\x-8);
}]
\def\xmin{-4} \def\xmax{4}
\def\ymin{-100} \def\ymax{100}

\draw[->] (\xmin,0)--(\xmax,0) node[below]{$x$};
\draw[->] (0,\ymin)--(0,\ymax) node[right]{$y$};
\draw (2,\ymax)--(2,\ymin) (-2,\ymax)--(-2,\ymin);
\draw[magenta,smooth,samples=100] 
plot[domain=-1.95:1.97] (\x,{f(\x)})
plot[domain=2.03:3.8]   (\x,{f(\x)})
plot[domain=-3.8:-2.05] (\x,{f(\x)});
\draw 
(0,50)--+(0:1mm)--+(180:1mm) node[left]{$50$}
(0,-50)--+(0:1mm)--+(180:1mm) node[left]{$-50$};
\path
(0,0) node[below left]{O} 
(2,0) node[below right]{$2$}
(-2,0) node[below left]{$-2$}
(current bounding box.north) node[above]
{The graph of $y=\frac{6x^2-3x+4}{2x^2-8}$};
\end{tikzpicture}
\end{document}
6

Hasty attempt with MetaPost and LuaLaTeX, using an old template of my own.

\documentclass[12pt,border=5mm]{standalone}
\usepackage{luatex85, luamplib}
    \mplibsetformat{metafun}
    \mplibtextextlabel{enable}
    \mplibnumbersystem{double}
\begin{document}
\begin{mplibcode}

vardef function(expr xmin, xmax, xstep)(text f_x) =
    save x; x := xmin;
    (x, f_x)
    forever: hide(x := x + xstep) exitif x > xmax;
        .. (x, f_x)
    endfor
    if x - xstep < xmax: hide(x := xmax) .. (x, f_x) fi
enddef;

u = v = .5cm;
xmax = -xmin = 15; ymax = -ymin = 20; xstep := .01;

vardef f(expr x) = (6(x**2)-3x+4)/(2(x**2)-8) enddef;

beginfig(1);

    drawoptions(withcolor green);
    draw (-2u, ymin*v) -- (-2u, ymax*v);
    draw (2u, ymin*v) -- (2u, ymax*v);
    draw (xmin*u, 3v) -- (xmax*u, 3v);

    drawoptions(withcolor red);
    draw function(xmin, -2.1, .xstep)(f(x)) xyscaled (u,v);
    draw function(-1.9, 1.95, xstep)(f(x)) xyscaled (u,v); 
    draw function(2.1, xmax, xstep)(f(x)) xyscaled (u,v);

    clip currentpicture to ((xmin, ymin) -- (xmax, ymin) -- (xmax, ymax) -- (xmin, ymax) -- cycle) xyscaled (u,v);

    drawoptions(withcolor black);
    drawarrow (xmin*u, 0) -- (xmax*u, 0);
    drawarrow (0, ymin*v) -- (0, ymax*v);

    for i = 1 upto floor(xmax.-1):
        draw (i*u, -2bp) -- (i*u, 2bp);
        draw (-i*u, -2bp) -- (-i*u, 2bp);
    endfor;

    for j = 1 upto floor(ymax-.1):
        draw (2bp, j*v) -- (-2bp, j*v);
        draw (2bp, -j*v) -- (-2bp, -j*v);
    endfor;

    label.bot("$x$", (xmax*u,0)); label.lft("$y$", (0, ymax*v));
    labeloffset := 5bp;
    label.bot("$-2$", (-2u,0)); label.bot("$2$", (2u, 0));
    label.lft("$3$", (0,3v));
endfig;

\end{mplibcode}
\end{document}

enter image description here

3

inspired by Franck Pastor's answer.

\documentclass[border=10pt]{standalone}
\usepackage{pst-plot}
\begin{document}
    \begin{pspicture}[algebraic,plotpoints=500](-15,-15)(15,15)
    \def\func{(6*x^2-3*x+4)/(2*x^2-8)}
    \psclip{%
        \psframe[fillstyle=solid,fillcolor=white,linestyle=none](-15,-15)(15,15)}
    \psplot[linecolor=blue,linewidth=1.5pt]{-15}{-2.01}{\func}
    \psplot[linecolor=blue,linewidth=1.5pt]{-1.99}{1.99}{\func}
    \psplot[linecolor=blue,linewidth=1.5pt]{2.01}{15}{\func}
    \endpsclip
    \psaxes[showorigin=false,labels=none]{->}(0,0)(-15,-15)(15,15)
    \psline[linecolor=green,linewidth=2pt](-2,-15)(-2,15)
    \psline[linecolor=green,linewidth=2pt](2,-15)(2,15)
    \psline[linecolor=green,linewidth=2pt](-15,2.8)(15,2.8)
    \uput[-90](-2,0){\LARGE $-2$}
    \uput[-90](2,0){\LARGE $2$}
    \uput[180](0,3){\LARGE $3$}
    \uput[-90](15,0){\LARGE $x$}
    \uput[180](0,15){\LARGE $y$}
    \end{pspicture}
\end{document}

enter image description here

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.