HI would you please get your help? Thank you so much (Matlab) - using matlab pro
ID: 3841098 • Letter: H
Question
HI would you please get your help?
Thank you so much
(Matlab) - using matlab program
Write a script to integrate a function by writing your own simple integration function. Compare your answer to trapz. Extra credit: +2 for using the average height, +1 for using an arbitrary number of divisions instead of 10 (have the user input the number of divisions Equation we're going to integrate: y(x) x3 x2 1. We're going to integrate from -1 to l, like lab 6. Print out your answer and compare it to integral.Explanation / Answer
The MATLAB code is given as:
p='Enter the number of steps';
n=input(p);
x=(-1:2/n:1);
f=-x.^3+x.^2+1;
s=0;
for i=1:n
h=(f(i)+f(i+1))/2;
w=x(i+1)-x(i);
s=s+h*w;
end
disp(s)
trapz(x,f)
Here we need n+1 xi where n is the number of steps.
The starting and stopping values of the vector are -1 and 1 respectively.
w has n values.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.