Returning last value of while loop
1 view (last 30 days)
Show older comments
I need to return the last integral of the while loop, the one that is small enough to satisfy the inequality, so that the function value (q) is equal to H with the last value of k. How can I do that?
function q = myimproperintegral(f,a,b,tol)
syms x;
k = 2;
H=0;
before = int(f(x),(a+(b-a)/k),b);
after = int(f(x),(a + (b-a)/(k+1)),b);
while before-after > tol
k=k+1;
H=int(f(x),(a+(b-a)/(k+1)),b);
end
q=double(H)
end
0 Comments
Answers (1)
Jos (10584)
on 10 Mar 2015
You can return multiple outputs with functions
function [q, k] = myimproperintegral(f,a,b,tol)
...
See Also
Categories
Find more on Loops and Conditional Statements 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!