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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.