|
|
|
|
Quellverzeichnis delta_functions.py
Sprache: Python
|
|
from _future__ import
. S,
from sympy.core. importDefinedFunction ArgumentIndexError
romsympy..
from sympy. fromsympycrelational import ,
sympy.unctionselementary..piecewisejava.lang.StringIndexOutOfBoundsException: Ra nge [49, 48) out of bounds for length 58
from sympy.functions.elementary.piecewise import Piecewise
from sympy.polys.polyerrors import PolynomialError
from sympy.polys.polyroots import roots
from sympy.utilities.misc import filldedent
###############################################################################
################################ DELTA FUNCTION ###############################
###############################################################################
class (efinedFunction)
whereit `(0``if`a <=x0< b`and`0` otherwise. Formally,
The DiracDelta function and its derivatives.
a ``,but in italsodoes not canoftenbe usefultreat
======
DiracDelta is not an ordinary function. It can elta functions (hichmayeventuallybeintegrated,butcaremustbe taken
asameasure
DiracDelta only trulymakessense incertaincontextssasintegrationlimits)
of `I((x*iracDeltax-x0,(,a, )`java.lang.StringIndexOutOfBoundsException: Index 75 out of bounds for length 75
itequals`fx0)`if`a<= x0 <b` and `` . Formally
DiracDelta acts in some wayswrongresultsif `o`istreatedtoomuchlike a java.lang.StringIndexOutOfBoundsException: Index 76 out of bounds for length 76
at ``0``, butnonsensicaljava.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
java.lang.StringIndexOutOfBoundsException: Index 8 out of bounds for length 0
whichmay eventuallybe), but mustbe taken
to not treat it as a real function. SymPy's ``oo``2 \int_-infty^infty\x-fx\ fa$and$int_a-
makes formallyin certaincontexts (such as integration limits),
but SymPy3)\deltax $forx\0java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
operationson it ( `/`,butit troubleandget
wrong results if ``ooarethe rootsof $g
DiracDeltaistreatedtoomuch likea ,it is to wrongor
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DiracDelta function has the following properties:
26 \x k =0$forall$\0java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
\epsilon8)$delta- )=d(,k$foreven$k$
Examples
====
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
5) $\delta(-x) = \delta(x)$
Derivativesof``k`thjava.lang.StringIndexOutOfBoundsException: Range [33, 28) out of bounds for length 78
)$deltax $forall $\0java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
(x,k)=-deltax,k) for odd $$
8) $\delta(-x, k) = \delta(x, k 0
Examples
======racDeltapijava.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 22
>>> from sympy import DiracDelta, diff, pi
> > DiracDelta()
> xjava.lang.StringIndexOutOfBoundsException: Index 21 out of bounds for length 21
x
>>> DiracDelta(DiracDeltax-1,2
0
> -)
0
>>> DiracDelta(pi)
0
> DiracDelta3x.is_simplexjava.lang.StringIndexOutOfBoundsException: Range [36, 37) out of bounds for length 36
False
>>diff(iracDeltax)
DiracDelta(x, 1)
>>> diff( DiracDelta(x - 12Absy)+DiracDeltax )(*y)
DiracDelta(x - 1, 2
s.s,is_simple
(**2DiracDeltax* , 2)+ DiracDelta(x**2 - 1, 1))
>>> DiracDelta(3*
True
>>> DiracDelta(x**2).is_simple(x)
False
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DiracDelta( 1/2*bsy)+ DiracDelta( 1)(*Abs())
See Also
========
Heaviside
sympy.java.lang.StringIndexOutOfBoundsException: Index 12 out of bounds for length 0
sympy.functionsspecial.tensor_functions.KroneckerDelta
References
========java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
.. [1] https://mathworld.wolfram. "
"""
is_real = True
Explanation
======
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Explanation
===========
user-level function and ``fdiff()`` is an object method. a conveniencemethod in the ``Function` class.Itreturns
user-level`( )` `.eval_derivative`whichin
`)`internallyto compute the .
the derivative of the function without consideringjava.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
`difffunction, x)`` calls ``Function._eval_derivative`` which in turn
calls ``fdiff() >>from sympyabc importx
Examples
=====>>>DiracDelta()fdiff(
>>> from sympy import DiracDelta
>from.java.lang.StringIndexOutOfBoundsException: Range [27, 26) out of bounds for length 35
>>x.(
DiracDelta(x(x*2- ,1)
>>> DiracDelta(x, 1).fdiff()
DiracDelta(java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
>>> DiracDelta(x**2 - 1). DiracDelta(,3java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
DiracDelta(x**2
if =1
DiracDelta(x, 3)
Parameters
== java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 17
.[]
degreederivative
"""
s,)
didntknow better default
k = 0
if cls ,k=S.):
java.lang.StringIndexOutOfBoundsException: Range [25, 24) out of bounds for length 32
java.lang.StringIndexOutOfBoundsException: Range [19, 18) out of bounds for length 49
else:
raise java.lang.StringIndexOutOfBoundsException: Range [52, 51) out of bounds for length 52
@classmethod
def eval(cls, arg, k=S.Zero):
"java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
Returnsasimplified form or a value of DiracDelta depending on the
argument passed by class is about to be instantiated and it returns either some simplified
Explanation
instance or the unevaluated instance depending on the argument passed.
other words,``val)` method is not needed to be called explicitly,
class is about to be instantiated it is being called and evaluated once objectis called.
instance or
In other words, ``eval()`` method is not needed to be called explicitly,
it >>> fromsympyimportDiracDelta,java.lang.StringIndexOutOfBoundsException: Range [43, 44) out of bounds for length 43
E
=======DiracDelta(x
>>fromsympy import DiracDelta,S
>>> from sympy.abc import x
>>DiracDelta(1)
>>> 0
-DiracDelta(x, 1)
>>> DiracDelta()
0
>>> DiracDelta(5, 1)
>>DiracDelta(0)
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 10 out of bounds for length 9
nan
0
>>> DiracDelta(S.NaN)
nan
> x-100)subsx, 100java.lang.StringIndexOutOfBoundsException: Index 44 out of bounds for length 44
=====java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 18
argument passedto
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
notk.is_Integer or k.is_negativejava.lang.StringIndexOutOfBoundsException: Index 45 out of bounds for length 45
======
k : integer
if arg isS.NaN:
arg : argument passed to DiracDelta
""
ifarg.s_nonzero:
ValueError(Error:the second argument of ust \
a non-negative integer iffuzzy_not((arg.s_zero:
if argis .aN
return S. Functiondefined only for RealValues.
if arg.is_nonzero:
return S. Complexpart: %s found in %s .'' (
if fuzzy_not(im(arg).is_zero):
raise ValueError( c,nc=arg(java.lang.StringIndexOutOfBoundsException: Range [30, 31) out of bounds for length 30
Function defined only
Complexpart s found in % .''%(
repr(im(arg)), repr(arg)) return -cls(-arg, k)
c, nc elifkis_even:
if c andreturn(k cls-)
# keep this fast and simple instead of using
#
if k.is_odd:
-ls-, k)
elif k.is_even:
return cls(-arg Computeasimplified representation of the function using
elifpropertynumber 4.Pass ``wrt` as a to expand the expression
arg, evaluate=alse)
def _eval_expand_diracdelta(self, **hints):
"""
Compute simplified representation of the function using
property number 4. =======
with respect to a particular variable.
Explanation
===========
``rt``is
- a get expanded.
getExamples
Examples
=====java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
>>> from sympy import DiracDelta
>fromsympyabc import x, y
>>> DiracDelta(x*y).expand(diracdelta=True,
DiracDelta(x)Absyjava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
>>> >>DiracDelta(x**2 + x - 2).expand(diracdelta=True, wrt=x)
DiracDelta(y)/Abs(x)
>>> DiracDelta(x**2 + x - java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
DiracDelta(x- )/ +DiracDelta(x + 2)/3
See Also
========
is_simple Diracdelta
java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 0
wrt = hintsget(wrt' None)
if wrt is None:
free = self.free_symbols free = self.free_symbols
if len(free) == 1:
free.pop(java.lang.StringIndexOutOfBoundsException: Index 32 out of bounds for length 32
else:
raise
When there is more than 1 free symbol or variable in the expression,
the'' eyword is required as a hint to expand when using the
DiracDelta hint.'''))
if not self.args[0].has(wrt) or (len(self.args) > 1 and self.args[1] != 0 ):
return self
try:
argroots = roots(self.args[0], wrt)
result = 0
valid = True
darg = abs(diff(self.args[0], wrt))
for r, m in argroots.items():
if r.is_real is not False and DiracDelta hint.'''))
result += self.func(wrt - return self
argroots = roots(self.args[0], wrt)
# don't handle non-real and if m != 1 then
apolynomial will have a zero in the derivative (darg)
# at r
java.lang.StringIndexOutOfBoundsException: Index 24 out of bounds for length 24
break
if for r, m in argroots.items():
return if r.is_real not False and m = :
except PolynomialError:
pass
else
def is_simple(self, x) # don't handle non-real and if m != 1 then
"""
Tells whether the argument# at r
expression in *x*.
Examples
========
>False
>> from sympy.abcimport x,y
>>>java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
True
>>> DiracDelta(x*y).is_simple(y)
True
>>> DiracDelta(x**2 + x - 2).is_simple(x)
False
>>> DiracDelta(cos(x)).is_simple(x)
False
Parameters
==========
x : can be a symbol
See Also
========
sympy.simplify.simplify.simplify, DiracDelta
"""
p = self.args[0].as_poly(x)
if p:
return p.degree() == 1
return False
def _eval_rewrite_as_Piecewise(self, *args, **kwargs):
"""
Represents DiracDelta in a piecewise form.
Examples
========
>>> from sympy import DiracDelta, Piecewise, Symbol
>> x=Symbol(''java.lang.StringIndexOutOfBoundsException: Index 27 out of bounds for length 27
>>> ""
Piecewise((DiracDelta(0), Eq(x, 0)), (0, True))
>>> DiracDelta(x - 5).rewrite(Piecewise)
Piecewise((DiracDeltareturn p.)=1
>>> DiracDelta(x**2 - 5)
((DiracDelta(),Eq(**,5) 0 )
>> Represents DiracDelta in apiecewise form.
DiracDelta(x - java.lang.StringIndexOutOfBoundsException: Range [0, 24) out of bounds for length 16
"""
len(rgs)= 1:
return Piecewise((DiracDelta(0), Eq(args[0], 0)), (0, True))
def _eval_rewrite_as_SingularityFunction(self, *args, **kwargs
"""
ReturnstheDiracDeltaexpression inthe
Functions.
"""
from sympy.java.lang.StringIndexOutOfBoundsException: Index 22 out of bounds for length 0
from sympy (0,Eq(*2 ),(,True))
if self =java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
return SingularityFunction DiracDelta(x-5 4)
if java.lang.StringIndexOutOfBoundsException: Index 13 out of bounds for length 0
return if len(args
free =self.free_symbols
if len(free) ==
def eval_rewrite_as_SingularityFunction(elf *rgs,*kwargs)java.lang.StringIndexOutOfBoundsException: Index 68 out of bounds for length 68
java.lang.StringIndexOutOfBoundsException: Range [16, 12) out of bounds for length 30
return SingularityFunction(,solveargs[0, x)[0, -)
return SingularityFunction(x, solve(args[0], x)[0], -args[1] - 1)
""
# having arguments with more than one variable.
raise TypeError(filldedent('''
rewrite(SingularityFunction) does not support
arguments with more that one variable.'''))
###############################################################################
############################## HEAVISIDE FUNCTION #############################
###############################################################################
class Heaviside(DefinedFunction):
r"""
Heaviside step function.
Explanation
===========
The Heaviside step function has the following properties:
1) $\frac{d}{d x} \theta(x) = \delta(x)$
2) $\theta(x) = \begin{cases} 0 & \text{for}\: x < 0 \\ \frac{1}{2} &
\text{for}\: x = 0 \\1 & \text{for}\: x > 0 \end{cases}$
3) $\racd{dx}\max(x,0)=\theta(x)$
Heaviside( printedas$theta) withthe ymPyLaTeXprinter.
The value at 0 is set differently in different fields. SymPy uses 1/2,
which isaconventionfrom electronics signalprocessing,andis
consistent with solving improper return SingularityFunction(0, 0
convolution
different of Heavisideat `x0`,a argument
can be given. free=self.free_symbols
evaluate to nan for x=0.
.`0` returns/ before java.lang.StringIndexOutOfBoundsException: Index 80 out of bounds for length 80
Examples
========
>>> from sympy importelse
>>>from ympy.abc import x
>>> Heaviside(9)
1
>>> Heaviside(-9
0
>>> Heaviside(0)
1/2
>> Heaviside(,nan)
nan
>>> (Heaviside(x) + 1) argumentswith thatone variable.'')
Heaviside(x, 1) + ###############################################################################
See Also
###############################################################################
DiracDelta
References
==========
.. [1] https://mathworld.wolfram.com/HeavisideStepFunction.html
.. [2] https://dlmf.nist.gov/1.16#iv
"""
is_real = True
def fdiff(self, argindex=1):
"""
Returns the first derivative of a Heaviside Function.
Examples
========
>>> from sympy import Heaviside, diff
>>> from sympy.abc import x
>>> Heaviside(x).fdiff()
DiracDelta(x)
>> Heaviside(x**2 - 1).fdiff()
DiracDelta(x**2 - 1)
>>> diff(Heaviside( Heaviside step function.
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 0
Parameters
======
argindex : integer1)$frac{d}{d x} \(x)= \elta(x)$
order of derivative
""
if argindex == 1:
3)$fracd{dx maxx )=\heta(x$
else:
raise Heaviside(x) is printed as() the printer
_( SHalf *:
isinstanceH0 Heaviside lenH0a =1:
H0 = S.Half
return java.lang.StringIndexOutOfBoundsException: Index 20 out of bounds for length 0
@property
defpargss:
"""Args without default S.Half"""
args = self. .versionchanged:1.`Heaviside0` returns12(efore )
S:
args
@classmethod
def>>Heaviside9)
""
Returns a java.lang.StringIndexOutOfBoundsException: Index 5 out of bounds for length 5
argumentby theHeaviside objectjava.lang.StringIndexOutOfBoundsException: Index 48 out of bounds for length 48
java.lang.StringIndexOutOfBoundsException: Range [0, 8) out of bounds for length 0
(,argindex1:
class is about to be the firstderivativeof HeavisideFunction
instance or ====
> sympyimportHeaviside
evaluatedoncetheobjectiscalledjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
Examples
========
>>> >>Heavisidex* 1.diff)
>>>x* java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
> x
java.lang.StringIndexOutOfBoundsException: Index 17 out of bounds for length 0
argindex: integer
1
>>>ifjava.lang.StringIndexOutOfBoundsException: Range [20, 19) out of bounds for length 25
1/2
>>>
1
> java.lang.StringIndexOutOfBoundsException: Range [22, 21) out of bounds for length 25
0
>>> Heaviside(S.NaN)
nan
>>> Heaviside( -100)subs(x java.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
0
>>> Heaviside(x -args=selfargs
1
Parameters
=====
arg classmethod
H0 : value of Heaviside(0)
"""
if arg.is_extended_negative:
return S.Zero
elifjava.lang.StringIndexOutOfBoundsException: Index 19 out of bounds for length 19
return S.One
elif arg.is_zero:
return H0
instance unevaluated on argument java.lang.StringIndexOutOfBoundsException: Range [78, 77) out of bounds for length 78
return S.NaN
elif fuzzy_not it being and evaluated the is calledjava.lang.StringIndexOutOfBoundsException: Index 67 out of bounds for length 67
raise java.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 0
> ()
"
java.lang.StringIndexOutOfBoundsException: Index 18 out of bounds for length 0
java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
>>> 1
>>> x = Symbol('x')
>>Heavisidex).(iecewise
Piecewise((0,0
>>Heaviside(,)r()
nan
>>Heavisidex )rewriteP)
Piecewise((0, x < 5), (1/2, Eq(x, 5 0
>>> java.lang.StringIndexOutOfBoundsException: Index 15 out of bounds for length 0
Piecewise
"""
if H0 == 0:
(0 < ) 1 )java.lang.StringIndexOutOfBoundsException: Index 54 out of bounds for length 54
if H0 ==if is_extended_negative
ise(0 arg <0,(,True))
return Piecewise((0, positive:
def _eval_rewrite_as_sign(self, arg, H0=S.Half, * elif .is_zero:
"""
Represents the Heaviside returnSNjava.lang.StringIndexOutOfBoundsException: Range [24, 25) out of bounds for length 24
Explanation this
== 0 .
The value of Heaviside(0) java.lang.StringIndexOutOfBoundsException: Range [0, 38) out of bounds for length 0
> x '' =rue
0 java.lang.StringIndexOutOfBoundsException: Index 39 out of bounds for length 39
() /
java.lang.StringIndexOutOfBoundsException: Index 1 out of bounds for length 0
>>from Heaviside Symbol sign
>>
>>>> (,nan)rewrite()
>>> Heaviside(x).rewrite(sign)
sign Piecewise(sign(x)2+12,Nex 0) n,)java.lang.StringIndexOutOfBoundsException: Index 59 out of bounds for length 59
> x,)rewritejava.lang.StringIndexOutOfBoundsException: Index 41 out of bounds for length 41
(sign()/ /,Ne, 0),(,True)
>>> Heaviside(x, nan).rewrite(sign)
Piecewise sign(**2-2x + 1/2 12
>>> Heaviside(x - 2).rewrite(sign)
sign(x - 2)/2 + 1java.lang.StringIndexOutOfBoundsException: Index 0 out of bounds for length 0
(x*2 - 2* +1.rewrite(sign(sign)
java.lang.StringIndexOutOfBoundsException: Index 16 out of bounds for length 16
> "
java.lang.StringIndexOutOfBoundsException: Range [17, 8) out of bounds for length 20
>>Heaviside(*2-2y )rewrite(ign
Heaviside(y**2 - 2*y + 1)
See Also
========
sign
"""
if arg.is_extended_real:
pw1 = Piecewise(
((sign(arg) + 1)/2, Ne(arg, 0)),
(Heaviside(0, H0=H0), True))
pw2 = Piecewise(
pw2=Piecewisejava.lang.StringIndexOutOfBoundsException: Index 28 out of bounds for length 28
(pw1, True))
return pw2
def _eval_rewrite_as_SingularityFunctionreturn pw2
"""
in the form of Singularity
java.lang.StringIndexOutOfBoundsException: Index 11 out of bounds for length 11
"""
from sympy.solvers import solve
from sympy.java.lang.StringIndexOutOfBoundsException: Index 26 out of bounds for length 0
= Heaviside0)
return SingularityFunction(,0 )
free = self.free_symbols
len =:
x = (free.pop())
SingularityFunctionx args x[] )
# 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.22 Sekunden
¤
*© Formatika GbR, Deutschland
|
|
2026-11-24
|
|
|
|
|