Graphics, Figures & TablesArea between two Curves

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Area between two Curves

Post by coachbennett1981 »

Morning,

I am having difficulty with filling the area between two curves. I am trying to write several examples for my students to do. Below I have two figures, of which the first, I have figured out how to shade using \pscustom. However, I can't figure out the second graph. I need the area filled on the interval from (0,1) and (1,2).

Any help would be appreciated


Nick

Code: Select all

\documentclass{exam}
 \usepackage{pst-plot}
 \pagestyle{empty}
 \begin{document}


\psset{unit=.65,arrowinset=0,arrowsize=8pt}
\psframebox[fillstyle=solid,fillcolor=black!10,framesep=0pt]{%
\begin{pspicture*}(-6,-10)(6,8.5)
  \pscustom[fillstyle=solid,fillcolor=blue!20,linestyle=none,algebraic]{%

    \psplot{-4}{3}{x^2-9}
  }
  \psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=red,arrows=<->]{-4.75}{5}{3-x}
\psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=blue,arrows=<->]{-4.15}{4}{x^2-9}

  \psaxes[arrowinset=0,arrowsize=8pt]{<->}(0,0)(-6,-10)(5,8)[$x$,-90][$y$,0]
\end{pspicture*}}


\psset{unit=3,arrowinset=0,arrowsize=8pt}
\psframebox[fillstyle=solid,fillcolor=black!10,framesep=0pt]{%
\begin{pspicture*}(-3,-5)(6,6)
  \pscustom[fillstyle=solid,fillcolor=blue!20,linestyle=none,algebraic]{%
  \psplot{0}{1}{x^2}
  \psplot{0}{1}{2-x^2}
  }
  \psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=red]{0}{2}{x^2}
\psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=blue]{0}{2}{2-x^2}

  \psaxes[arrowinset=0,arrowsize=8pt]{<->}(0,0)(-2,-2)(5,5)[$x$,-90][$y$,0]
\end{pspicture*}}



 \end{document}

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10334
Joined: Mon Mar 10, 2008 9:44 pm

Area between two Curves

Post by Stefan Kottwitz »

Hi Nick,

give a complete path. You can also swap interval limits. This fills between the two curves in the second plot, I only swapped plot arguments before closing the path:

Code: Select all

\psset{unit=3,arrowinset=0,arrowsize=8pt}
\psframebox[fillstyle=solid,fillcolor=black!10,framesep=0pt]{%
\begin{pspicture*}(-3,-5)(6,6)
  \pscustom[fillstyle=solid,fillcolor=blue!20,linestyle=none,algebraic]{%
  \psplot{0}{1}{x^2}
  \psplot{1}{0}{2-x^2}
  \closepath
  }
  \psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=red]{0}{2}{x^2}
\psplot[arrowinset=0,arrowsize=8pt,linewidth=2pt,algebraic,linecolor=blue]{0}{2}{2-x^2}

  \psaxes[arrowinset=0,arrowsize=8pt]{<->}(0,0)(-2,-2)(5,5)[$x$,-90][$y$,0]
\end{pspicture*}}
curves.png
curves.png (11.73 KiB) Viewed 4676 times
Stefan
LaTeX.org admin
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Re: Area between two Curves

Post by coachbennett1981 »

Cool.. I was so close.. Thank you for taking time to fix this for me. How could I include the interval [1,2]? I am having trouble with that too


Nick
User avatar
Johannes_B
Site Moderator
Posts: 4182
Joined: Thu Nov 01, 2012 4:08 pm

Area between two Curves

Post by Johannes_B »

I would simply think adding the following can do the trick. I have to say, that i have no experience with pstricks.

Code: Select all

\pscustom[fillstyle=solid,fillcolor=blue!20,linestyle=none,algebraic]{%
			\psplot{1}{2}{x^2}
			\psplot{2}{1}{2-x^2}
			\closepath
		}
The smart way: Calm down and take a deep breath, read posts and provided links attentively, try to understand and ask if necessary.
coachbennett1981
Posts: 274
Joined: Fri Feb 05, 2010 10:15 pm

Re: Area between two Curves

Post by coachbennett1981 »

Thanks.. I was using the interval from (1,2) for both functions. Thanks for your time
Post Reply