Int vs Integral; Int giving wrong results

조회 수: 4 (최근 30일)
James Mathews
James Mathews 2016년 1월 4일
답변: Christopher Creutzig 2018년 3월 21일
Suppose I have the function
p=@(x) (heaviside(x-0.2)-heaviside(x-0.3)).*(x.^3+x.^2+x+1)+(heaviside(x-0.3)-heaviside(x-0.8)).*(-3*x.^3-2*x.^2+3*x+0.77)
which basically comes from using cubic splines to interpolate functions. I want to calculate the integral of p(r)^2/r between 1 and some number S, ideally symbolically.
If I do integral then I get:
integral( @(s)(p(s)).^2./s,1,0.3)=-1.601
If instead I use int:
syms S
g=matlabFunction(int( @(s)(p(s)).^2./s,1,S),'Vars', {S});
g(0.3)=0
Clearly the int is giving the wrong result, but I don't know why. This example comes from a much more complicated example where integral gives the right result, and in the other case int gives non zero results but they are very wrong.
I would like to use int but I need to understand why it is giving such wrong results!
Thanks,
James

답변 (2개)

Christopher Creutzig
Christopher Creutzig 2018년 3월 21일
As the documentation says down in the “Tips” section, int(f,1,S) assumes that 1 ≤ S. In that region, your input function is 0, so int returning 0 is correct. Call int(f,S,1) to get a result valid for S ≤ 1.

Walter Roberson
Walter Roberson 2016년 1월 4일
int() does not take a function handle as an argument.
syms s
g = matlabFunction( int((p(s)).^2./s,1,S), 'vars', S);

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by