- #1
gfd43tg
Gold Member
- 950
- 50
https://www.physicsforums.com/attachments/72086
https://www.physicsforums.com/attachment.php?attachmentid=72087&d=1407804589
Hello
Here is the code for the adaptive stepsize function
I am wondering if I did it correctly, or better yet if just by looking at the graph I would be able to tell the values of ##x## which are evaluated. This can't be plotted to test, so it's clear this was a contrived graph to test the student's understanding of how adaptive stepsize integration works. I am just wondering what would indicate the places that would be checked.
From what I see, 2 and 10 would be looked at. Then also 6 and 8, since there is a sharp turn at those locations, and a step could be placed there. But my calculations are saying that it's also evaluated at 7 and 9.
https://www.physicsforums.com/attachment.php?attachmentid=72087&d=1407804589
Hello
Here is the code for the adaptive stepsize function
Code:
function I = arttrap(fh,a,b,tol,fa,fb)
if nargin == 4
fa = fh(a); fb = fh(b);
end
m = (a+b)/2;
fm = fh(m);
h = b-a;
% Compute I based on 1 subdivision
I1 = 0.5*(fa+fb)*h;
% Compute I based on 2 subdivisions
I2 = (fa + 2*fm + fb)*h/4;
% Compare both estimates
if abs(I1-I2)<tol
I = I2;
else
ILeft = artrap(fh,a,m,tol/2,fa,fm);
IRight = artrap(fh,m,b,tol/2,fm,fb);
I = ILeft + IRight;
end
disp(['a = ' num2str(a) ', b=' num2str(b)]);
I am wondering if I did it correctly, or better yet if just by looking at the graph I would be able to tell the values of ##x## which are evaluated. This can't be plotted to test, so it's clear this was a contrived graph to test the student's understanding of how adaptive stepsize integration works. I am just wondering what would indicate the places that would be checked.
From what I see, 2 and 10 would be looked at. Then also 6 and 8, since there is a sharp turn at those locations, and a step could be placed there. But my calculations are saying that it's also evaluated at 7 and 9.
Last edited: