1

I want too trace a graph for this function f(x)=-x²/(x+1)² but when I use tkz-fct I have this problem " Dimension too large "

This is my code:

\documentclass[twoside]{report}
\usepackage[a4paper, left=1.5cm, right=1.5cm]{geometry}
\usepackage{etex}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[explicit,calcwidth]{titlesec}
\usepackage{amsthm,amsfonts}
\usepackage{amsmath,amssymb,graphicx,multicol,mathrsfs, enumerate,kpfonts,eurosym,alterqcm,enumitem,tabularx,variations,pifont,multirow}
\usepackage[francais]{babel}

\usepackage[np]{numprint}
\usepackage[usenames,dvipsnames,svgnames,table]{xcolor}
\usepackage[many,most]{tcolorbox}
\usepackage{tkz-base}
\usepackage{tkz-fct}
\usetikzlibrary{babel}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\tkzInit[xmin=-4,xmax=4,ymin=-6,ymax=6,xstep=2,ystep=2]
\tkzAxeXY
\tkzFct[color=red,samples=400,domain=-4:3]{(-1*x**2)/(x+1)**2 -2}
\end{tikzpicture}

\end{document}

Thank you for your answers

Torbjørn T.
  • 206,688
habib
  • 61
  • 3
  • I tried with the same code what you posted, but doesn't show any error, may update your TeX setup will fix the issue (PS: I am using MikTeX version 2.9) – MadyYuvi Sep 26 '17 at 11:21
  • 1
    @MadyYuvi You need to enable shell-escape because tkz-fct "outsources" the computations to gnuplot. I get the same error with pdflatex --shell-escape file.tex. (Unsurprisingly, as you're dividing by zero, or very close to zero.) – Torbjørn T. Sep 26 '17 at 11:24

2 Answers2

1

I'm not that familiar with tkz-fct, but if using pgfplots instead is an option, you can try the following. The key point is the restrict y to domain key, which enables you to discard all computed values outside a certain domain.

output of code

\documentclass[twoside]{report}
\usepackage[a4paper, left=1.5cm, right=1.5cm]{geometry}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[francais]{babel}
\usepackage{pgfplots}
\usetikzlibrary{babel}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}
\begin{axis}[
  xmin=-4,xmax=4,
  ymin=-6,ymax=6,
  width=6cm,height=6cm,
  xtick distance=2,ytick distance=2,
  domain=-4:4,
  samples=500,
  axis lines=middle
]
\addplot [
  red,
  % discard all y-values outside given domain
  restrict y to domain=-6:6
] {(-1*x^2)/(x+1)^2 -2};
\end{axis}
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688
1

tkz-fct is far less sophisticated than pgfplots. You have to deal with the discontinuities on your own.

\documentclass{article}
\usepackage{tkz-fct}        

\begin{document}
\begin{tikzpicture}
\tkzInit[xmin=-6,xmax=6,ymin=-10,ymax=10,xstep=2,ystep=2]
\tkzAxeXY
\tkzFct[color=red,samples=400,domain=(-6):(-3)]{(-1*x**2)/(x+1)**2 -2}
\tkzFct[color=red,samples=400,domain=-1.5:4]{(-1*x**2)/(x+1)**2 -2}
\end{tikzpicture}
\end{document}

enter image description here

Alain Matthes
  • 95,075