integrating discontinuous function

조회 수: 4 (최근 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