Drawing Integral

View: New views
7 Messages — Rating Filter:   Alert me  

Drawing Integral

by xlogo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello everyone,

I tried to draw the area between two curves: (I join a picture test.png
to show the result)

The first curve is defined by the function f(x)=x^2
The second curve is defined by the function g(x)=-x+3

I want to draw their area on the interval -4:2
f(2)=4; g(2)=1
f(-4)=16

I wrote this code:
----------------------------------------------------------
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\usetikzlibrary{scopes}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{uququq}{rgb}{0.25,0.25,0.25}
\begin{tikzpicture}[>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=uququq] (-5.86,0) -- (6.82,0);
\foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5,6}
\draw[shift={(\x,0)},color=uququq] (0pt,2pt) -- (0pt,-2pt)node[below]
{\x};
\draw[->,color=uququq] (0,-0.78) -- (0,9.12);
\foreach \y in {,1,2,3,4,5,6,7,8,9}
\draw[shift={(0,\y)},color=uququq] (2pt,0pt) -- (-2pt,0pt)node[left]
{\y};
\draw[color=uququq] (0pt,-10pt) node[right] {0};
\clip(-5.86,-0.78) rectangle (6.82,9.12);
\draw[color=zzttqq,fill=zzttqq,fill opacity=0.1]
{[smooth,samples=50,domain=-4.0:2.0] plot(\x,{\x^2})} -- (2,1)
{[smooth,samples=50,domain=2.0:-4.0] -- plot(\x,{-\x+3})} -- (-4,16) --
cycle;
\end{tikzpicture}
\end{document}
------------------------------------------------------------------------
The last line with the \draw instruction doesn't work on screen.
Thanks in advance if anyone could help me.

Best

Loïc


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

test.png (22K) Download Attachment

Re: Drawing Integral

by xlogo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Hello,

In fact, I realize that the problem wasn't my "draw line" but only the
fact that there is a bug with the sign "minus" at the beginning of a
mathematical expression.

For example:

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\begin{document}
\begin{tikzpicture}
\draw[domain=-4:2] plot (\x,{-\x});
\end{tikzpicture}
\end{document}

Try to compile and you'll see the problem.
Otherwise, with 0-\x, it works:

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\begin{document}
\begin{tikzpicture}
% Look at the new expression
\draw[domain=-4:2] plot (\x,{0-\x});
\end{tikzpicture}
\end{document}

Anyone has ever revealed this bug?

regards
Loïc

Le samedi 19 juillet 2008 à 14:16 +0200, Loïc a écrit :

> Hello everyone,
>
> I tried to draw the area between two curves: (I join a picture test.png
> to show the result)
>
> The first curve is defined by the function f(x)=x^2
> The second curve is defined by the function g(x)=-x+3
>
> I want to draw their area on the interval -4:2
> f(2)=4; g(2)=1
> f(-4)=16
>
> I wrote this code:
> ----------------------------------------------------------
> \documentclass[10pt]{article}
> \usepackage{pgf,tikz}
> \usetikzlibrary{arrows}
> \usetikzlibrary{scopes}
> \pagestyle{empty}
> \begin{document}
> \definecolor{zzttqq}{rgb}{0.6,0.2,0}
> \definecolor{uququq}{rgb}{0.25,0.25,0.25}
> \begin{tikzpicture}[>=triangle 45,x=1.0cm,y=1.0cm]
> \draw[->,color=uququq] (-5.86,0) -- (6.82,0);
> \foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5,6}
> \draw[shift={(\x,0)},color=uququq] (0pt,2pt) -- (0pt,-2pt)node[below]
> {\x};
> \draw[->,color=uququq] (0,-0.78) -- (0,9.12);
> \foreach \y in {,1,2,3,4,5,6,7,8,9}
> \draw[shift={(0,\y)},color=uququq] (2pt,0pt) -- (-2pt,0pt)node[left]
> {\y};
> \draw[color=uququq] (0pt,-10pt) node[right] {0};
> \clip(-5.86,-0.78) rectangle (6.82,9.12);
> \draw[color=zzttqq,fill=zzttqq,fill opacity=0.1]
> {[smooth,samples=50,domain=-4.0:2.0] plot(\x,{\x^2})} -- (2,1)
> {[smooth,samples=50,domain=2.0:-4.0] -- plot(\x,{-\x+3})} -- (-4,16) --
> cycle;
> \end{tikzpicture}
> \end{document}
> ------------------------------------------------------------------------
> The last line with the \draw instruction doesn't work on screen.
> Thanks in advance if anyone could help me.
>
> Best
>
> Loïc
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________ pgf-users mailing list pgf-users@... https://lists.sourceforge.net/lists/listinfo/pgf-users



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Drawing Integral

by xlogo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Now, it's easy to draw the picture with:

\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{zzttqq}{rgb}{0.6,0.2,0}
\definecolor{uququq}{rgb}{0.25,0.25,0.25}
\begin{tikzpicture}[>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=uququq] (-5.86,0) -- (6.82,0);
\foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5,6}
\draw[shift={(\x,0)},color=uququq] (0pt,2pt) -- (0pt,-2pt)node[below]
{\x};
\draw[->,color=uququq] (0,-0.78) -- (0,9.12);
\foreach \y in {,1,2,3,4,5,6,7,8,9}
\draw[shift={(0,\y)},color=uququq] (2pt,0pt) -- (-2pt,0pt)node[left]
{\y};
\draw[color=uququq] (0pt,-10pt) node[right] {0};
\clip(-5.86,-0.78) rectangle (6.82,9.12);
\draw[color=zzttqq,fill=zzttqq,fill opacity=0.1]
{[smooth,samples=50,domain=-4.0:2.0] plot(\x,{\x^2})} -- (2,1)
{[smooth,samples=50,domain=2.0:-4.0] -- plot(\x,{0-\x+3})} -- (-4,16) --
cycle;
\end{tikzpicture}
\end{document}

Bye

Loïc




Le mardi 22 juillet 2008 à 23:40 +0200, Loïc a écrit :

> 
> Hello,
>
> In fact, I realize that the problem wasn't my "draw line" but only the
> fact that there is a bug with the sign "minus" at the beginning of a
> mathematical expression.
>
> For example:
>
> \documentclass[10pt]{article}
> \usepackage{pgf,tikz}
> \begin{document}
> \begin{tikzpicture}
> \draw[domain=-4:2] plot (\x,{-\x});
> \end{tikzpicture}
> \end{document}
>
> Try to compile and you'll see the problem.
> Otherwise, with 0-\x, it works:
>
> \documentclass[10pt]{article}
> \usepackage{pgf,tikz}
> \begin{document}
> \begin{tikzpicture}
> % Look at the new expression
> \draw[domain=-4:2] plot (\x,{0-\x});
> \end{tikzpicture}
> \end{document}
>
> Anyone has ever revealed this bug?
>
> regards
> Loïc
>
> Le samedi 19 juillet 2008 à 14:16 +0200, Loïc a écrit :
> > Hello everyone,
> >
> > I tried to draw the area between two curves: (I join a picture test.png
> > to show the result)
> >
> > The first curve is defined by the function f(x)=x^2
> > The second curve is defined by the function g(x)=-x+3
> >
> > I want to draw their area on the interval -4:2
> > f(2)=4; g(2)=1
> > f(-4)=16
> >
> > I wrote this code:
> > ----------------------------------------------------------
> > \documentclass[10pt]{article}
> > \usepackage{pgf,tikz}
> > \usetikzlibrary{arrows}
> > \usetikzlibrary{scopes}
> > \pagestyle{empty}
> > \begin{document}
> > \definecolor{zzttqq}{rgb}{0.6,0.2,0}
> > \definecolor{uququq}{rgb}{0.25,0.25,0.25}
> > \begin{tikzpicture}[>=triangle 45,x=1.0cm,y=1.0cm]
> > \draw[->,color=uququq] (-5.86,0) -- (6.82,0);
> > \foreach \x in {-5,-4,-3,-2,-1,1,2,3,4,5,6}
> > \draw[shift={(\x,0)},color=uququq] (0pt,2pt) -- (0pt,-2pt)node[below]
> > {\x};
> > \draw[->,color=uququq] (0,-0.78) -- (0,9.12);
> > \foreach \y in {,1,2,3,4,5,6,7,8,9}
> > \draw[shift={(0,\y)},color=uququq] (2pt,0pt) -- (-2pt,0pt)node[left]
> > {\y};
> > \draw[color=uququq] (0pt,-10pt) node[right] {0};
> > \clip(-5.86,-0.78) rectangle (6.82,9.12);
> > \draw[color=zzttqq,fill=zzttqq,fill opacity=0.1]
> > {[smooth,samples=50,domain=-4.0:2.0] plot(\x,{\x^2})} -- (2,1)
> > {[smooth,samples=50,domain=2.0:-4.0] -- plot(\x,{-\x+3})} -- (-4,16) --
> > cycle;
> > \end{tikzpicture}
> > \end{document}
> > ------------------------------------------------------------------------
> > The last line with the \draw instruction doesn't work on screen.
> > Thanks in advance if anyone could help me.
> >
> > Best
> >
> > Loïc
> > -------------------------------------------------------------------------
> > This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> > Build the coolest Linux based applications with Moblin SDK & win great prizes
> > Grand prize is a trip for two to an Open Source event anywhere in the world
> > http://moblin-contest.org/redirect.php?banner_id=100&url=/
> > _______________________________________________ pgf-users mailing list pgf-users@... https://lists.sourceforge.net/lists/listinfo/pgf-users
>
>
>
> -------------------------------------------------------------------------
> This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
> Build the coolest Linux based applications with Moblin SDK & win great prizes
> Grand prize is a trip for two to an Open Source event anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> pgf-users mailing list
> pgf-users@...
> https://lists.sourceforge.net/lists/listinfo/pgf-users



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Drawing Integral

by Brian Rantz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/7/22 Loïc <xlogo@...>:

Hello,

In fact, I realize that the problem wasn't my "draw line" but only the
fact that there is a bug with the sign "minus" at the beginning of a
mathematical expression.


Well, I'm not getting this ``bug'' at all. Which version of PGF are you using?

-Brian,


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Drawing Integral

by xlogo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using pgf 2.00 and I'm compiling with PDFLaTeX

Loïc

Le mercredi 23 juillet 2008 à 04:31 +0100, Brian Rantz a écrit :

> 2008/7/22 Loïc <xlogo@...>:
>        
>         Hello,
>        
>         In fact, I realize that the problem wasn't my "draw line" but
>         only the
>         fact that there is a bug with the sign "minus" at the
>         beginning of a
>         mathematical expression.
>
>
> Well, I'm not getting this ``bug'' at all. Which version of PGF are
> you using?
>
> -Brian,
>
>
>



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Drawing Integral

by Brian Rantz :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2008/7/23 Loïc <xlogo@...>:
I'm using pgf 2.00 and I'm compiling with PDFLaTeX

Loïc

Ah well, I'm using the latest CVS version. You would need to update your files, or try (at least in the examples you give) remove the braces as they are only necessary if a calculation contains ( or ), for example plot(\x,\x^2) not \plot(\x,{\x^2}).

-Brian


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users

Re: Drawing Integral

by xlogo :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Yes, you're right. If I remove the braces {} it works.

Many thanks for this tip

Loïc

Le mercredi 23 juillet 2008 à 08:16 +0100, Brian Rantz a écrit :

> 2008/7/23 Loïc <xlogo@...>:
>         I'm using pgf 2.00 and I'm compiling with PDFLaTeX
>        
>         Loïc
>
> Ah well, I'm using the latest CVS version. You would need to update
> your files, or try (at least in the examples you give) remove the
> braces as they are only necessary if a calculation contains ( or ),
> for example plot(\x,\x^2) not \plot(\x,{\x^2}).
>
> -Brian
>
>
>



-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
pgf-users mailing list
pgf-users@...
https://lists.sourceforge.net/lists/listinfo/pgf-users
LightInTheBox - Buy quality products at wholesale price