integrating discontinuous function

23 次查看(过去 30 天)
Lam
Lam 2011-3-21
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.

回答(1 个)

Andrew Newell
Andrew Newell 2011-3-21
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 个评论
Susan
Susan 2011-5-25
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 2011-5-26
Thanks for pointing that out, Susan. I have corrected the answer.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Mathematics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by