#๐Ÿ”’ why is the integral 0?

4 messages ยท Page 1 of 1 (latest)

grave wraith
#

i wrote this thing in np and it works for d(k)*2 but not for d(k)*3 for that i get 0
output:

$\displaystyle - \frac{\max\left(0, - k + x\right)}{k^{2}} + \frac{\max\left(0, - k + x, \min\left(k, x\right)\right)}{k^{2}}$
$\displaystyle \frac{- \max\left(0, - k + x\right) + \max\left(0, - k + x, \min\left(k, x\right)\right)}{k^{2}}$
$\displaystyle 0$

code:

import sympy as sp
from typing import Callable

Dist = Callable[[sp.Symbol], sp.Expr]
sp.init_printing()

input, k = sp.symbols('x k', real=True)
d1, d2 = sp.symbols('d1 d2', cls=sp.Function)

def d(y: sp.Symbol) -> Dist:
    return lambda x: sp.Piecewise(
        (1/y, (0 < x) & (x < y)),
        (0, True),
    )

def SUM(dist1: Dist, dist2: Dist) -> Dist:
    t = sp.symbols('t', real=True)
    return lambda x: sp.integrate(dist1(t) * dist2(x-t), (t, -sp.oo, sp.oo)).doit()

dsum = SUM(d(k), d(k))(input)

print(dsum._repr_latex_())

dsum_simplified = sp.simplify(
    dsum
    .doit())

print(dsum_simplified._repr_latex_())

def MULT(dist1: Dist, n: int) -> Dist:
    dist_res = dist1
    for _ in range(n-1):
        dist_res = SUM(dist_res, dist1)
    return dist_res

dmult = MULT(d(k), 3)(input)
dmult = sp.simplify(dmult.doit())

print(dmult._repr_latex_())
grim patrolBOT
#

@grave wraith

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

grim patrolBOT
#

@grave wraith

Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.