Improper Integral calculation within a tolerance

1 view (last 30 days)
function r = myimproperintegral(f,a,b,tol)
syms x;
first = int(f,x,a+(b-a)/2,b);
second = int(f,x,a+(b-a)/3,b);
z = 4;
while ((second - first) > tol)
first = second;
second = int(f,x,a+(b-a)/z,b);
z = z+1;
end
r = second;
This is the current function I have written so far in attempt to calculate an improper integral to a certain tolerance, but for some reason when I test it with some values i get an error in the while loop condition that states "Conversion to logical from sym is not possible". Any insight on this would be appreciated as I'm not sure what is going on, thanks.
  1 Comment
Geoff Hayes
Geoff Hayes on 1 Mar 2015
Hugo - put a breakpoint at the line for
first = int(f,x,a+(b-a)/2,b);
and then run the code. When the debugger pauses at this line, step over it. What is the value for first? Step over the next line. What is the value for second?
See this tutorial for tips on debugging in MATLAB.

Sign in to comment.

Answers (0)

Categories

Find more on Symbolic Math Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!