How to plot graph regarding the definite integral by using Midpoint rule for the function 𝑦 =x^1/3?
Mostra commenti meno recenti
This is what I have done and I'm not sure is it correct.
I don't know how to continue to plot the graph of it.
y = @(x) nthroot(x,3); %Function to integrate
a = 0; b = 2; %Interval where a is the lower boundary and b is the upper boundary.
n = 10; %Number of subintervals
dx = (b-a/n); %Width of each rectangle
mpr = 0;
for i = a:dx:b
mpr = mpr + f(i+dx/2);
end
I = dx*mpr;
4 Commenti
Compare the exact & approximated ones using Midpoint rule
f = @(x) nthroot(x,3); %Function to integrate ...assign to correct variable
a = 0; b = 2; %Interval where a is the lower boundary and b is the upper boundary.
n = 10; %Number of subintervals
dx = (b-a)/n; % width
mpr = 0;
x = linspace(a,b,100);
y = f(x);
plot(x,y,'linewidth',2)
hold on
L = a:dx:b;
for i = 2:numel(L)-1
mpr = mpr + f((L(i)+L(i-1))/2);
plot((L(1) + (i-0.5)*dx), f((L(i)+L(i-1))/2),'r+','linewidth',2)
end
I = dx*mpr
legend('Exact: y = x^{1/3}','Approx (Midpoint)','location','best')
grid
Should be
plot((L(1) + (i-1-0.5)*dx), f((L(i)+L(i-1))/2),'r+','linewidth',2)
instead of
plot((L(1) + (i-0.5)*dx), f((L(i)+L(i-1))/2),'r+','linewidth',2)
These are the evaluation points for the Midpoint rule. I don't know what you mean by Approx(Midpoint) in the legend. These are not approximations for an integral.
VBBV
il 6 Mar 2024
Yes, you are right.
L
il 7 Mar 2024
Risposta accettata
Più risposte (0)
Categorie
Scopri di più su Spectral Measurements in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



