3

I used Geogebra to draw the graph of the function $y = 2x^2 - 4x$. This is my code

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\pagestyle{empty}
\begin{document}
\psset{xunit=1.0cm,yunit=1.0cm,algebraic=true,dotstyle=o,dotsize=3pt 0,linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-2,-2.44)(3.92,5)
\psaxes[labelFontSize=\scriptstyle,xAxis=true,yAxis=true,Dx=1,Dy=1,ticksize=-2pt 0,subticks=2]{->}(0,0)(-2,-2.44)(3.92,5)[,140] [y,-40]
\psplot[linewidth=1.6pt,plotpoints=200]{-2.0}{3.9165217391304363}{2*x²-4*x}
\psline[linewidth=1.6pt,linestyle=dashed,dash=3pt 3pt](1,-2)(1,0)
\psline[linewidth=1.6pt,linestyle=dashed,dash=2pt 2pt](1,-2)(0,-2)
\begin{scriptsize}
\psdots[dotstyle=*,linecolor=blue](1,-2)
\rput[bl](1.02,-1.93){\blue{$A$}}
\psdots[dotstyle=*,linecolor=blue](1,0)
\rput[bl](1.02,0.08){\blue{$B$}}
\psdots[dotstyle=*,linecolor=blue](0,-2)
\rput[bl](0.02,-1.93){\blue{$C$}}
\end{scriptsize}
\end{pspicture*}
\end{document}

I use Texmaker and compiler with keys F2 -> F4 ->F8 ->F7. But I got enter image description here

How can I get correct picture?

5

the function is not correct:

\psplot[linewidth=1.6pt,plotpoints=200]{-2.0}{3.9165217391304363}{2*x^2-4*x}

you have {2*x²-4*x}. An exponent must be written as x^2

However, the export of GeoGebra is not really nice. Use:

\documentclass[10pt]{article}
\usepackage{pstricks-add}
\pagestyle{empty}
\begin{document}

\psset{algebraic,linewidth=0.8pt,arrowsize=3pt 2,arrowinset=0.25}
\begin{pspicture*}(-2,-2.44)(3.92,5)
\psaxes[labelFontSize=\scriptstyle,ticksize=-2pt 0,subticks=2]{->}(0,0)(-2,-2.44)(3.92,5)[,140] [y,-40]
\psplot[linewidth=1.6pt,plotpoints=200]{-2.0}{3.9165217391304363}{2*x^2-4*x}
\psCoordinates[linecolor=blue,linestyle=dashed](1,-2)
\psdots[dotstyle=*,linecolor=blue](1,0)(0,-2)
\scriptsize
\rput[bl](1.02,-1.93){\blue{$A$}}
\rput[bl](1.02,0.08){\blue{$B$}}
\rput[bl](0.02,-1.93){\blue{$C$}}
\end{pspicture*}

\end{document}

enter image description here

4

A recommended solution for best practitioners.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-plot}
\usepackage{pst-eucl}

\psset
{
    algebraic,
    arrowsize=3pt 2,
    arrowinset=0.25,
    plotpoints=200,
    saveNodeCoors,
}

\def\func(#1){2*(#1)^2-4*(#1)}

\begin{document}
\begin{pspicture}(-2,-2.5)(4,5)
\psplot[linecolor=red,yMaxValue=4]{-2.0}{4}{\func(x)}
\psaxes[labelFontSize=\scriptstyle,ticksize=-4pt 0,subticks=2,linecolor=lightgray]{->}(0,0)(-2,-2.5)(3.5,4.5)[$x$,0][$y$,90]
\everypsbox{\scriptsize\color{blue}}
\pstGeonode[linecolor=blue,PosAngle={90,-90,-135}](1,0){B}(*N-B.x {\func(x)}){A}(0,|A){C}
\psline[linestyle=dashed,linecolor=blue](B)(A)(C)
\end{pspicture}
\end{document}

enter image description here

Edit

I just knew by a trial and error that (x,y|P) can be simplified as (x,|P). And its dual, (P|x,y) can be simplified as (P|,y). I don't know whether it is a useful bug or a by-design feature.

Be careful, the yMaxValue apparently depends on plotpoints. A pessimistic approach is to use a large plotpoints (for example 5000) to make a better resolution, but the file size becomes bigger. :-)

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.