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 Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by