integrating discontinuous function

4 visualizaciones (últimos 30 días)
Lam
Lam el 21 de Mzo. de 2011
Hi there, I want to wirte a program which can integrating a defined function as follows
function f=r(x,p) if x<=0 f=0; else f=x^p; end
and use sybolic integration tool to integrate defined function
int(r(y-a),a,x));
the problem is matlab does not know whether to select f=0 or f=x^p.
please show me a way to solve the problem
Thanks
L.

Respuestas (1)

Andrew Newell
Andrew Newell el 21 de Mzo. de 2011
Did you define your symbolic variables first?
syms a x y p
You'll need to give a numeric value for p or else int won't be able to evaluate it:
p=2;
You can redefine your function in terms of a heaviside function. Now you can integrate it:
fint = int(heaviside(y-a)*(y-a)^p,a,x)
fint =
-(a - x)^3/3
If you want to get an answer for a given a and x, you can substitute:
subs(fint,{a,x},{sym(-1),sym(1)})
ans =
8/3
double(ans)
ans =
2.6667
EDIT: As Susan points out, this gives the wrong answer for a<x. This seems to occur because one of the integral limits, a, is also a parameter in the equation. This code gives the correct answer:
syms a x x0 x1 y p
p=2;
fint = int(heaviside(y-a)*(y-a)^p,y,x0,x1);
subs(fint,{x0,x1},{a,x})
ans =
-(heaviside(x - a)*(a - x)^3)/3
subs(fint,{x,a},{sym(2),sym(1)})
ans =
1/3
subs(fint,{x,a},{sym(1),sym(2)})
ans =
0
  5 comentarios
Susan
Susan el 25 de Mayo de 2011
I guess I'm being dense here, but it seems that the heaviside function has had no effect. Shouldn't answers for x<a be zero?
syms a x y p
p=2;
fint = int(heaviside(y-a)*(y-a)^p,a,x)
subs(fint,{a,x},{sym(0),sym(-3)})
fint =
-(a - x)^3/3
ans =
-9
Andrew Newell
Andrew Newell el 26 de Mayo de 2011
Thanks for pointing that out, Susan. I have corrected the answer.

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics 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!

Translated by