Write a script that prompts the user to input a function fx
Write a script that prompts the user to input a function, f(x), and the limits of integration, a and b. The script should approximate the integral of the function from a to b, using the Trapezoid Rule. The script should also generate a plot of the function AND the piecewise-linear approximation to the function used in the Trapezoid Rule. Fully annotate the plot, including a legend.
Solution
Try this:
x=linspace(a,b,N);
N=input(\'define n=\');
a=input(\'lower limit=\');
b=input(\'upper limit=\');
x=linspace(a,b,N);
h=(b-a)/(N-1);
for i=1:N-1;
T=T+h*(f(x(i))+f(x(i+1)))/2;
end
plot(a,b)
