Integrating peicewise functions with symbolic bounds
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I'm trying to integrate a peicewise function. The following code illustrates the problem I'm running into:
clearvars
syms x z real
f = symfun(piecewise(-1/2<=x<=1/2,1,0),x);
int(f(x),x,0,1)
int(f(x),x,z,1)
When the function is integrated over [0,1], I get 1/2 as an answer. But when I try to put a symbolic lower bound, the result is 0, contradicting the fact that at z = 0 the integral should be 1/2. I've done the following to try to resolve this:
1) Use indefinite integrals and subs in the lower + upper bounds. This is tricky because matlab just returns the integration of each part of the peicewise function; when I substitute I get the integral over the peicewise integral that doesn't include the mass located in the lower peicewise sets.
piecewise(x in Dom::Interval([-1/2], [1/2]), x, 0)
I know that's a little confusing; not sure how to more clearly explain it. My best guess is that Matlab's internal code is making a similar mistake when I have z as a symbolic lower bound.
2) Add an assumeAlso which sets z < 1 in case there was some error due to ordering of the bounds. No change.
3) Used Heaviside functions instead. This gives me the correct answer in this specific case but kills matlab's ability to process my later code; I'm writing a multi-stage value function and matlab hangs on their symbolic definitions if my mass functions are defined using Heaviside rather than peicewise functions.
Any ideas on what I should try next?
0 comentarios
Respuestas (1)
Torsten
el 10 de Feb. de 2017
syms x z
y=piecewise(-1/2<=x<=1/2,1,0);
inty=int(y,x,z,1);
does not work ?
Best wishes
Torsten.
3 comentarios
Ver también
Categorías
Más información sobre Assumptions en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!