# Area between two curves

I need help writing a code to calculate the area between two curves -- there are two in which I need help with. I want to use either the tikzpicture or pgfplots package. As you can see, one is black and white, and the other has two areas coloured in different colours. I need the point of intersection and the regions labeled. Any suggestions?

• Are you sure that LaTeX is the right tool for this? Exact computation should not be done with it, you should use a tool more suited for computing integrals (examples could be gnu-octave, matlab, python with numpy, and so on). – Skillmon Jan 7 '18 at 13:34
• R=1/3-2\pi : wolframalpha.com/input/?i=integrate+x%5E2-sin(pi*x%2F2)+between+0+and+1. For the BW image how do you expect to use tizk or pgfplots? – anderstood Jan 7 '18 at 13:38
• Please add a minimal working example (MWE) of what you've tried so far, and the formulae of the linked image (and put it on the post, not only the link). – CarLaTeX Jan 7 '18 at 16:56
• You may want to change the word "calculate" in your first sentence to "typeset" or "draw". If you really mean calculate, don't use LaTeX. (See other comments.) If you mean draw, then you should make a real attempt at it yourself. Research the problem. There are similar examples easily found (Google). Do your best to modify one to your needs and present your code in a MWE. Then tell the community what additions/changes you can't figure out. "Please do this for me" posts are typically not answered, are certainly looked down upon, and are not the intent of TeX.SX. – Sandy G Jan 7 '18 at 23:31

Answering a question without an MWE gives a wrong signal, but the temptation was too great.

I leave the second image to you as an exercise.

If you have a lot of pictures like this in your document, it's better to use standalone and \includegraphics or \tikzexternalize.

\documentclass{article}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{positioning, arrows.meta}

\newcommand{\mysin}[1]{plot[domain=#1, samples=300] (\x,{sin(3.14*\x/2 r)})}
\newcommand{\myparabola}[1]{plot[domain=#1, samples=300] (\x,{\x*\x})}

\begin{document}
\begin{center}
\begin{tikzpicture}[x=4cm, y=4cm, >=Stealth]
% area under sin
\fill[cyan!30!white] \mysin{0:1} -- (1,0) -- cycle;
% area under parabola
\fill[yellow!30!white] \myparabola{0:1} -- (1,0) -- cycle;
% segment to (1,1)
\draw[yellow, thick] (1,0) -- (1,1)
node[black, above right=-2pt and 3pt] {$\left(1,1\right)$};
% axes
\draw[black, <->] (-.5,0) -- (1.25, 0)
node[black, below left=4pt and 2pt] {$x$};
\draw[black, <->] (0,-.5) -- (0,1.5)
node[black, below left=4pt and 2pt] {$y$};
% sin
\draw[blue, <->, thick] \mysin{-.3:1.25}
node[black, right] {$y=\sin \left(\dfrac{\pi x}{2}\right)$};
% parabola
\draw[red, <->, thick]  \myparabola{-.5:1.2}
node[black, right] {$y=x^{2}$};
% area labels
\node at (.5, .5) {$R$};
\node at (.75, .25) {$S$};
% ticks
\draw (0,1) -- +(2pt,0)
(0,1) -- +(-2pt,0);
\draw (1,0) -- +(0,2pt)
(1,0) -- +(0,-2pt);
\end{tikzpicture}
\end{center}
\end{document}