|
|
|
|
Impressum delta_functions.py
Sprache: Python
|
|
_future__ annotations
from from sympycore import S,diff
.unction import ,ArgumentIndexError
from sympy.coref .core.logic import fuzzy_not
from .ore.Eq, Ne
from sympy.functions.elementary from sympyfunctions.complexes import im, sign
from sympy.functions.elementary import Piecewise
from sympy.polys.polyerrors import PolynomialError
from sympy.polys.polyroots import roots
from sympy.utilities.misc import filldedent
###############################################################################
################################ DELTA FUNCTION ###############################
###############################################################################
class DiracDelta(DefinedFunction):
r """
The DiracDelta function and its derivatives.
Explanation
===========
DiracDelta is not an ordinary function. It can be rigorously defined either
as a distribution or as a measure.
DiracDelta only makes sense in definite java.lang.StringIndexOutOfBoundsException: Index 58 out of bounds for length 58
integralsDiracDelta(:
equals`f() ` < =b` `0`. java.lang.StringIndexOutOfBoundsException: Range [80, 79) out of bounds for length 80
DiracDelta
t`0` but manyways it not.It be useful to
DiracDelta======java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 15
d functions w eventually be ) must be taken
to not treat it as a distribution or .
truly formally in certain (uch as limits)
but integrals theform ``ntegral(f)*iracDelta( ) x a, b)`,
operations on it (like ``1/oo``), but it is easy where it `(x0)` ` <= x0 < ``and `0`otherwise. Formally,
`o` anumber.Similarly,if
DiracDelta is treated too much like a function, it is easy to get wrong or
results.
DiracDelta function has the following properties:
1) $\frac{d}{d x} \theta(x) delta functions( may eventually be integrated), butcare must taken
)$int_{\}\ delta( -a)(),dx=() \{-
\epsilon}^{a+\epsilon} \delta(x - a)f(x)\, dx = truly sense formally in certain (such as integration limits),
3)$\delta()=0 all $ neq $
4) $\delta(g(x)) = \sum_i \frac{\delta(x - x_i)}{\|g operations on it (ike `1oo`) iseasy to get into trouble
the roots of $g$
5) $\delta(-x) = \delta(x) like function is easy to get wrong
Derivatives of ``k``-th order of java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 0
)$delta(, k) = 0 all $x neq $
7) $\delta(-x, k) = -\delta(x, k)$ for odd $k$
8)\delta(-x,k \elta(, ) $$
=====
>>> from sympy import DiracDelta, java.lang.StringIndexOutOfBoundsException: Range [0, 42) out of bounds for length 31
``k`- order of DiracDelta have the following properties:
>> 6 \delta(,k)=0 $ neq $
DiracDelta(x)
>>> DiracDelta(1)
0
>>> 7) $\delta-, \(,$for $java.lang.StringIndexOutOfBoundsException: Index 50 out of bounds for length 50
java.lang.StringIndexOutOfBoundsException: Range [5, 6) out of bounds for length 5
racDelta()
0
>>> DiracDelta(x - 4).subsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DiracDelta(0)
>>diff(x)
>>DiracDelta()
>>> diff(DiracDelta(x - 1), x, DiracDelta()
( -1 )
>>> diff 0
>>DiracDelta(1java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
>> DiracDelta(*).is_simple()
True
>>> DiracDelta(x**2).is_simple(x)
False
>> DiracDelta()java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
)/(2*() DiracDelta( +1/(2Abs()
See Also
== )
Heaviside
ympy.implify.simplify.implify is_simple
2*2x**DiracDelta(*2-1 java.lang.StringIndexOutOfBoundsException: Range [51, 50) out of bounds for length 64
java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 8
.. [1] https://mathworld. x-1)(*() x+1)2Absy)
"""
is_real.java.lang.StringIndexOutOfBoundsException: Range [28, 27) out of bounds for length 59
def fdiff(self, argindexjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
""
Returns the first derivative java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
======
The difference between ``java.lang.StringIndexOutOfBoundsException: Range [0, 37) out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Range [12, 8) out of bounds for length 79
available``
the derivative of the function without considering the chain rule.
``ifffunction, x` calls`Function_eval_derivative` in turn
calls `fdiff(` compute thederivativeofthefunctionjava.lang.StringIndexOutOfBoundsException: Index 79 out of bounds for length 79
Examples
========
>>> from sympy import `(java.lang.StringIndexOutOfBoundsException: Range [24, 23) out of bounds for length 79
> .bc java.lang.StringIndexOutOfBoundsException: Index 35 out of bounds for length 35
> x.)
DiracDeltajava.lang.StringIndexOutOfBoundsException: Range [18, 0) out of bounds for length 0
>>> DiracDelta(x, 1).fdiff >> from sympy.abc import x
DiracDelta(x, 2)
> >>DiracDelta()fdiff)
DiracDeltax* -1,1java.lang.StringIndexOutOfBoundsException: Index 31 out of bounds for length 31
>>> diff(DiracDelta(java.lang.StringIndexOutOfBoundsException: Range [0, 29) out of bounds for length 0
DiracDeltax )
Parameters
==========
argindex : integer
degree of derivative
argindex = :
#I didn't know if there is a better way to handle default arguments)
k=0
if len(self.args) > 1:
k =self.args[]
return of
else:
raise ArgumentIndexError(elf argindex)
@ #I' know if there isa waytohandle default arguments
def eval(cls,arg =SZero
" k=self.args[1]
Returns a simplified form or a value of DiracDelta depending return self.func(self.args[0], k + 1)
ArgumentIndexError(self,argindex)
Explanation
=java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 0
The ``eval()` java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 75
java.lang.StringIndexOutOfBoundsException: Range [42, 41) out of bounds for length 79
or java.lang.StringIndexOutOfBoundsException: Range [55, 54) out of bounds for length 78
Inwords e(` to java.lang.StringIndexOutOfBoundsException: Range [80, 79) out of bounds for length 80
the java.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 80
========
sympy , S
>>> from sympy.abc import x
xamples
(x)
> import DiracDelta java.lang.StringIndexOutOfBoundsException: Range [43, 44) out of bounds for length 43
-DiracDelta(x, 1
> java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 25
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
> >>> DiracDelta1java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
0
>> 0
>>> DiracDelta(-1)
0
>>> DiracDelta
>>> java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
0
>>DiracDelta( 100).(, 100)
DiracDelta(0)
Parameters
======
k : integer
arg: argumentpassed to DiracDelta
"""
if is_Integerork:
raise ValueError("Error=====
a non-negative integer, %s given
NaNjava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
return "
.
returnraise" DiracDeltam be\
if im)i)
raise ValueError( if isSN:
only java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
'' %(
repr(im(arg)), repr(java.lang.StringIndexOutOfBoundsException: Range [0, 39) out of bounds for length 38
, =.args_cnc()
if c and c[0] is S.NegativeOne:
# keep this fast and simple instead of using
n
if k. Complex part:% s.''
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 36
.java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 27
return cls-arg, )ifk else (arg)
elif k
return could_extract_minus_sign
def return -ls(arg, k)
"""
java.lang.StringIndexOutOfBoundsException: Range [29, 28) out of bounds for length 65
4 `wrt` hintto
with respect return cls(Fjava.lang.StringIndexOutOfBoundsException: Range [43, 42) out of bounds for length 43
ajava.lang.StringIndexOutOfBoundsException: Range [46, 43) out of bounds for length 65
====java.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
``java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
`` :
===
>>> from sympy import DiracDelta
>>> from sympy.java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
>>> DiracDelta>> from sympy.x java.lang.StringIndexOutOfBoundsException: Range [38, 39) out of bounds for length 38
>x/()
DiracDelta(y)/Abs(x)
> java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 67
DiracDelta(x java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 28
See Also
======= 13+java.lang.StringIndexOutOfBoundsException: Range [41, 40) out of bounds for length 49
,
"""
.',)
wrtis:
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 36
if len(wrt =free)
wrt = free.pop()
java.lang.StringIndexOutOfBoundsException: Range [17, 16) out of bounds for length 80
When there is wrtkjava.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 76
the '
java.lang.StringIndexOutOfBoundsException: Range [23, 22) out of bounds for length 33
if not self.args[0].has(wrt) or (len(self.args) > 1 and self.args[1] != 0 ):
try:
java.lang.StringIndexOutOfBoundsException: Range [22, 20) out of bounds for length 47
result = 0 java.lang.StringIndexOutOfBoundsException: Range [35, 34) out of bounds for length 76
valid = True
darg = abs(diff(self.args[0], wrt))
java.lang.StringIndexOutOfBoundsException: Range [17, 12) out of bounds for length 41
is m=1:
result += self.funcexcept
:
# don't handle non-real and if m != 1 then
# a polynomial will have a zero in the derivative (darg)
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 26
break
if valid:
return result
except PolynomialError:
pass
return self
def is_simple(self, x):
"""
Tells whether the argument(args[0]) of DiracDelta is a linear
expression in *x*.
Examples
========
>>> from sympy import DiracDelta, cos
>>> from sympy.abc import x, y
>>> DiracDelta(x*y).is_simple(x)
True
>>> DiracDelta(x*y).is_simple(y)
True
>>> DiracDelta(x**2 + x
>>> . x
False
Parameters
==========
x : can be aTrue
> (x')
========
sympy.simplify.
"java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
p = self.args[0]java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
if p:
.egree()= 1
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
def _PiecewiseDiracDelta0 x*,),(,True)
"""
in form.
Examples
========
>>> from sympy import
>>> if( =java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
>>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
>>> DiracDelta( writtenin formofSingularity
java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
>>> DiracDelta(x**2 - 5).rewrite(Piecewise)
Piecewise(DiracDelta() Eqx*,5) 0 ))
>>> DiracDelta(x - 5, 4).rewrite(Piecewise)
-,4)
"""
args) == 1:
return Piecewise
_s,* *:
"""
Returns en(args) == 1:
Functions x ([0] x[] -java.lang.StringIndexOutOfBoundsException: Index 71 out of bounds for length 71
"
3f{} }max x$
from x)is \(x$ S java.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72
if self = electronicsand java.lang.StringIndexOutOfBoundsException: Range [72, 73) out of bounds for length 72
, -1)
if self == DiracDelta(0, .
To specify a value `=`,second
.
if len java.lang.StringIndexOutOfBoundsException: Range [13, 12) out of bounds for length 28
x = (free. .. versionchanged:: 19 `Heaviside()`now 12(:undefined)
if len(args) == 1:
return SingularityFunction(x, solve(args
return java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 12
:
# I don't know how to handle the case for DiracDelta expressions> s.abcjava.lang.StringIndexOutOfBoundsException: Range [30, 29) out of bounds for length 31
# having arguments with more than one variable.-)
raise java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
> 0 java.lang.StringIndexOutOfBoundsException: Index 25 out of bounds for length 25
more variable.')
###############################################################################
############################## HEAVISIDE FUNCTION #############################
###############################################################################
>java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 39
r"""
java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
Explanation
===========
The ======
)\theta d($
2) $\
"java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
\{}{ } \ax(,0 theta(x)java.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
$\theta(x$with SymPy LaTeX printer.
The
whichdef _new__(cls,arg,H0=.Half,*options)
consistentif (H0,Heaviside)and(.rgs)= java.lang.StringIndexOutOfBoundsException: Range [59, 60) out of bounds for length 59
convolution.
To specify a different value of Heaviside at ``x=0``, a second
can be given. def pargs(elf)java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
evaluate to nan for x=0.
.. : 1. `Heaviside()`now 1/ b: undefined)
Examples
======= if args[1]is .Half
>> return args
>>> java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 0
>>(java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 20
1
>>> Heaviside(-9)
0
>>> Heaviside(0)
1/2
>> passed object.
nan
>>> (Heaviside(x) + 1).replace(Heaviside(x), Heaviside(x, 1))
Heaviside(x, 1) + 1
See Also
========
DiracDelta
References
==========
.. [1] https://mathworld.wolfram.com/HeavisideStepFunction.html
. Explanation
"""
is_real = True
deffdiffself =)
"""
Returns first aHeaviside Function.
Examples
=====
>>from sympy ,diff
>>> from sympy.abc and once the .
>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DiracDelta(x)
>>> (*2- 1)f(java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
acDelta(*2-1)
>>> diff(Heaviside(
>>Heaviside()
Parameters
==========
: integer
order of
"""
if argindex == 1:
return DiracDelta(self.args[0])
else:
raise ArgumentIndexError(self, argindex
def __java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 9
>> Heaviside(-5)
H0 = S.Half
return super(clsjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
@property
def pargs(self >>Heavisidex .(,5)
"""Args without java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 9
args =.
if
args = args[:1]
return ======
@
java.lang.StringIndexOutOfBoundsException: Index 7 out of bounds for length 0
"""
Returns a java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 11
argument passed by the java.lang.StringIndexOutOfBoundsException: Index 36 out of bounds for length 25
Explanation
===========
The ``eval()`` method is automatically called when the ``Heaviside``
class is about to java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 25
orthe unevaluated instancedepending the passed.
In other words, ``eval()``returnNaN
iscalled andevaluatedonceobject .
Examples
========
>>> from sympy import Heaviside, S
>>> from sympy.abc import x
>>> Heaviside(x)
Heaviside
>>Heaviside(19)
""
>>> Heaviside(0)
Examples
>>> Heaviside(0, 1)
java.lang.StringIndexOutOfBoundsException: Index 9 out of bounds for length 9
>>> Heaviside(- > ()rewriteP)
0
> xnan.ewritePiecewise
> ( -5.(iecewisejava.lang.StringIndexOutOfBoundsException: Index 47 out of bounds for length 47
>>> Heaviside(x
1
Parameters
==========
arg java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
H0 : value of returnPiecewise(,arg =0,(,True)
"""
arg.:
return S. return Piecew(,arg ) 1 ))
positive:
java.lang.StringIndexOutOfBoundsException: Index 14 out of bounds for length 0
elifarg.is_zero:
return H0
elif arg is S.NaN:
S.aN
elif fuzzy_not(im(arg).is_zero):
raise ValueError("Function defined only for Real Values. Complex part: %s found in %s ." % (repr(im(arg)), repr(arg)) )
def _eval_rewrite_as_Piecewise(self, arg, H0=None, **kwargs):
"""
Represents Heaviside in a Piecewise form.
Examples
========
>>> from sympy import Heaviside, Piecewise, Symbol, nan
>>> x = Symbol('x')
>>> Heaviside(x).rewrite(Piecewise)
Piecewise((0, x < 0), (1/2, Eq(x, 0)), (1, True))
>>> Heaviside(x,nan).rewrite(Piecewise)
Piecewise((0, x < 0), (nan, Eq(x, 0)), (1, True))
>>> Heaviside(x - 5).rewrite(Piecewise)
Piecewise((0, x < 5), (1/2, Eq(x, 5)), (1, True))
>>> Heaviside(x**2 - 1).rewrite(Piecewise)
Piecewise((0, x**2 < 1), (1/2, Eq(x**2, 1)), (1, True))
"""
if H0 == 0:
return Piecewise((0, arg <= 0), (1, True))
if H0 == 1:
return Piecewise((0, arg < 0), (1, True))
return Piecewise((0, arg < 0), (H0, Eq(arg, 0)), (1, True))
def _eval_rewrite_as_sign(self, arg, H0=S.Half, **kwargs):
"""
Represents the Heaviside function in the form of sign function.
Explanation
===========
The value of Heaviside(0) must be 1/2 for rewriting as sign to be
strictly equivalent. For easier usage, we also allow rewriting
when Heaviside() is undefinedjava.lang.StringIndexOutOfBoundsException: Range [39, 40) out of bounds for length 39
Examples
========
>>> from sympy import Heaviside, Symbol, sign, nan
>> x =Symbol(x, real=rue)
>whenHeaviside()isundefined.
>>> Heaviside(x).rewrite(sign)
signx)2+12
>>> Heaviside(x, 0).rewrite(sign)
>> from sympy import Heaviside,Symbol,sign,nan
>>Heaviside(x ).rewritesignjava.lang.StringIndexOutOfBoundsException: Index 43 out of bounds for length 43
(/ / (,),(an,True)
>>> Heaviside(x - 2).rewrite(sign)
sign(x - 2)/2 + >>Heaviside(x, 0.rewrite(sign)
>> Piecewise(()/+12 (x 0) 0 )java.lang.StringIndexOutOfBoundsException: Index 57 out of bounds for length 57
(x* * )2+/
java.lang.StringIndexOutOfBoundsException: Range [0, 1) out of bounds for length 0
Heaviside(y)
>>> Heaviside(y**2 - 2*y + 1).rewrite(sign)
>>> Heaviside*2-2*+)
See Also
========
sign
"""
if arg. Heaviside(y)
pw1 = Piecewise(
((sign > y* *+1.s)
(Heaviside(0, H0=H0), True))
(
((sign(arg) + 1)/2, Eq(Heaviside(0, H0=H0), S.Half)),
(java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
pw2
def _Returns the Heaviside expression written form of Singularity
"""
Returns the Heaviside expressionjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Functions.
"""
ifself =Heaviside(:
from sympy. SingularityFunction(0 ,0java.lang.StringIndexOutOfBoundsException: Range [47, 48) out of bounds for length 47
if if (free)==1java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 26
return SingularityFunction(0, return (x,solve(,)0],0
free = self.free_symbols
if len(free) == 1:
x = (free.pop())
return SingularityFunction(x, solve(args, x)[0], 0)
# TODO
# ((x - 5)**3*Heaviside(x - 5)).rewrite(SingularityFunction) should output
# SingularityFunction(x, 5, 0) instead of (x - 5)**3*SingularityFunction(x, 5, 0)
else:
# I don't know how to handle the case for Heaviside expressions
# having arguments with more than one variable.
raise TypeError(filldedent('''
rewrite(SingularityFunction) does not
support arguments with more that one variable.'''))
¤ Dauer der Verarbeitung: 0.36 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|