Int vs Integral; Int giving wrong results
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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
0 Kommentare
Antworten (2)
Christopher Creutzig
am 21 Mär. 2018
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.
0 Kommentare
Walter Roberson
am 4 Jan. 2016
int() does not take a function handle as an argument.
syms s
g = matlabFunction( int((p(s)).^2./s,1,S), 'vars', S);
0 Kommentare
Siehe auch
Kategorien
Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!