Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello! I need some help. I am trying to use a while loop and quad to calculate t

ID: 3587999 • Letter: H

Question

Hello! I need some help. I am trying to use a while loop and quad to calculate the integral of f(x) over the interval [a,b] for a= 1/6, 1/6^2, 1/6^3, ... until successive integrals differ by less than some small number t. Can somebody evaluate my code and let me know where problems may be? Since it is an improper integral i am increasing b to b+1 in the loop, is that correct?Thanks!

function IN = myimproperintegral1(f,b,t)

P2 = quad(f,1/6,b);
P1 = quad(f,1/6,b);
i = b;

j=1;

while abs(P2 - P1) > t
P2 = quad(f,(1/6)^j,i + 1);
i = i + 1;
j=j+1;
P1 = quad(f,(1/6)^j,i + 1);
end
P1;
end

Explanation / Answer

P2 = quad(f,1/6,b);
P1 = quad(f,1/6,b);
i = b;

j=1;

while abs(P2 - P1) > t
P2 = quad(f,(1/6)^j,i + 1);
i = i + 1;
j=j+1;
P1 = quad(f,(1/6)^j,i + 1);
end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote