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

Write a function myinteg which calculates the integral of the Matlab built-in hu

ID: 3569396 • Letter: W

Question

Write a function myinteg which calculates the integral of the Matlab built-in humps function by using mytrap function. The humps function has the following form: humps(x)=(x-0.3)^2+ 0.01+ (x-0.9)^2+ 0.04-6 Function myinteg should ask the user for the lower bound a, upper bound b and the number of intervals n with which the numerical integral will be calculated. Function myinteg will then calculate vectors x and f and call the function mytrap to calculate the integral. The elements of vectors x and f are calculated as: xi=xi-1+ delta x, i=1 to n, x 0=a fi= humps(xi) i = 0 to n (Note that there is no need to input n and Ax to the function mytrap because both n and Ax can be calculated from the input vector x .) Your function has to check the input arguments entered by the user and provide error report if the input arguments are not in accordance with the following rules: - the input numbers a and b satisfy the condition a

Explanation / Answer

function [y]=myinteg(a,b,n)
if a>b
disp('lower bound is greater than upper bound!!!')
y=-1;
else
if isinteger(n) || n<0
disp('wrong input for n')
y=-1;
else
f=@(x) (1./((x-0.3).^2+0.01))+(1./((x-0.9).^2+0.04))-6;
h=(b-a)/n;
x1=a:h:b;
y1=f(x1);
y=mytrap(x1,y1);
end
end
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