[pstricks] si-function
José Emilio Vila Forcén
Jose.Vila at cui.unige.ch
Thu Dec 15 17:03:07 CET 2005
Dear Herbert,
I found very impressive your example with integration. I did't know
that it was possible to do that. I have modified slightly the code: my
objective is to calculate:
y(x) = \int_a^b f(x,t)dt
In my example it is working, but I didn't test it extensively. the new
macro is
\integrate{x_min}{x_max}(a,b){function}
where function takes two arguments: t x FUNC. For example, 1 GAUSS takes
first the value of 'x' and lately the mean of the distribution.
a and b are the limits of integration and x_min and x_max the limits for
the x-axis of the plot.
Regards
Jose
\documentclass{article}
\usepackage{pst-plot}
\usepackage{pst-math,pst-func}
\makeatletter
\def\cummulativeI{\pst at object{cummulativeI}}
\def\cummulativeI at i#1#2#3{%
\begin at SpecialObj%
\addto at pscode{
/a #1 def
/dx #2 #1 sub \psk at plotpoints\space div def
/b a dx add def
/scx { \pst at number\psxunit mul } def
/scy { \pst at number\psyunit mul } def
tx at FuncDict begin /SFunc { #3 } def end
a scx 0 moveto
\psk at plotpoints 1 sub {
a b \psk at Simpson % a b M on Styack
tx at FuncDict begin Simpson I end % y value on stack
scy b scx exch lineto
/b b dx add def
} repeat
stroke
}%
\end at SpecialObj%
}
\def\integrate{\pst at object{integrate}}
\def\integrate at i#1#2(#3,#4)#5{%
\begin at SpecialObj%
\addto at pscode{
/a #3 def
/dx #4 #3 sub \psk at plotpoints\space div def
/b #4 def
/aa #1 def
/dd #2 #1 sub \psk at plotpoints\space div def
/bb aa dd add def
/scx { \pst at number\psxunit mul } def
/scy { \pst at number\psyunit mul } def
tx at FuncDict begin /SFunc { bb #5 } def end
a b \psk at Simpson % a b M on Stack
tx at FuncDict begin Simpson I end % y value on stack
scy bb scx exch moveto
/bb bb dd add def
\psk at plotpoints 1 sub {
a b \psk at Simpson % a b M on Stack
tx at FuncDict begin Simpson I end % y value on stack
scy bb scx exch lineto
/bb bb dd add def
} repeat
stroke
}%
\end at SpecialObj%
}
\makeatother
\begin{document}
\psset{xunit=0.5cm,yunit=1cm}
\begin{pspicture}(-10,-.5)(10,4)
\psaxes[dx=1cm,Dx=2]{->}(0,0)(-10,0)(10,4)
\cummulativeI[plotpoints=200,Simpson=10]{-10}{10}{0 1 GAUSS}
\integrate[plotpoints=200,Simpson=10,linecolor=red]{-10}{10}(-10,10){1
GAUSS}
\end{pspicture}
\end{document}
More information about the PSTricks
mailing list