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

Create a program that calculates the integral for part a and part b (give some o

ID: 3573066 • Letter: C

Question

Create a program that calculates the integral for part a and part b (give some option to choose a or b) using the trapezoidal rule, k = 4.

1. (Practice) Evaluate the following integrals by using the trapezoidal rule: Evaluate To for one panel by using Equation 14.6. Compute 11 by using the value of To and Equation 14.11. Continue the calculation through T4. Collect your results in the form of a table. (Be careful: Errors in one step carry over into the next.) a. x2 dx (Exact result -170.667) (Exact result 6553.6)

Explanation / Answer

choice = input('a or b: ', 's');
if choice == 'a'
    y = @(x) x^2;
    a = 0;
    b = 8;
    n = 4;
    h = (b-a)/n;
    ys = [];
    xs = [];
    for i=a:h:b
        xs(end+1) = i;
        ys(end+1) = y(i);
    end
    l = length(xs);
    answer = (h/2)*((ys(1)+ys(l))+2*(sum(ys)-ys(1)-ys(l)))
else
    y = @(x) x^4;
    a = 0;
    b = 8;
    n = 4;
    h = (b-a)/n;
    ys = [];
    xs = [];
    for i=a:h:b
        xs(end+1) = i;
        ys(end+1) = y(i);
    end
    l = length(xs);
    answer = (h/2)*((ys(1)+ys(l))+2*(sum(ys)-ys(1)-ys(l)))
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