ASKSAGE: Sage Q&A Forum - Latest question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 16 Jan 2021 08:57:53 -0600Integration of multivariable piecewise function in SageMathhttps://ask.sagemath.org/question/55306/integration-of-multivariable-piecewise-function-in-sagemath/ I have a problem that can be simplified as below:
g(w) = piecewise([[[0, 3], (w-3)^2], [(3, infinity), 0]])
f(w,t) = g*cos(w*t) # t >= 0
#assume(t, 'real')
h = integral(f, w, 0, 10); h
> Out: t |--> undef
If I do not use piecewise, and integrate only up to w = 3 (where I know g becomes zero), then I obtain the wanted solution:
g2(w) = (w-3)^2
f2(w, t) = g2*cos(w*t)
h2 = integral(f2, w, 0, 3); h2
> Out: t |--> 6/t^2 - 2*sin(3*t)/t^3
How can I integrate f(w, t) defining g(w) piece-wisely (or equivalent)?J. SerraSat, 16 Jan 2021 08:57:53 -0600https://ask.sagemath.org/question/55306/Integrate piecewise function with change of variablehttps://ask.sagemath.org/question/37114/integrate-piecewise-function-with-change-of-variable/I would like to integrate a piecewise defined function while operating a change of variable. I start by defining the function and another variable involved in the change of variable:
phi(x) = piecewise([([-1,1], (1-abs(x))*(1-abs(x))*(1+2*abs(x)))]);
phi(x) = phi.extension(0);
h=pi/n;
h=h.n();
What I would like to do is integrate the function `phi(x/h-1)` between `0` and `pi` so I try it and results in
integral(phi(x/h-1),x,0,pi)
ValueError: substituting the piecewise variable must result in real number
So I then try to use another variable which I try to define to be 'real'
t=var('t')
assume(t,'real');
integral(phi(t/h-1),t,0,pi)
but it results in the same error... Now I try the "lambda" method since it worked when calling the `plot` function with the same change of variable; but fail again
integral(lambda t: phi(t/h-1),t,0,pi)
TypeError: unable to convert <function <lambda> at 0x16d71f140> to a symbolic expression
Now I try to use another integration method with `definite_integral` but get the same errors, only different for the "lambda" method
definite_integral(lambda x: phi(x/h-1),x,0,pi)
TypeError: cannot coerce arguments: no canonical coercion from <type 'function'> to Symbolic Ring
Is there any way around this? I really do not know what else to try...
jrojasquTue, 28 Mar 2017 18:28:56 -0500https://ask.sagemath.org/question/37114/