![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176239/image.png)
plot a graph showing the convergence of a Integral versus the number of sample points used.
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Shipeng YANG
il 6 Mag 2017
Risposto: Ali Haider
il 13 Apr 2022
Use Simpson's rule to evaluate the integral of sinx^3 from 0 to 2pi, and plot the convergence of the integral versus the number of sample points used
0 Commenti
Risposta accettata
Gautham Sholingar
il 15 Mag 2017
Modificato: Gautham Sholingar
il 15 Mag 2017
The following example on file exchange (MATLAB Central) is one implementation of the Simpson's rule integration:
After you download the function, add it to your path and run the following code snippet:
numSamplePoints = 1000;
I = zeros(numSamplePoints,1);
for samplePoints = 1:numSamplePoints
% samplePoints
I(samplePoints) = simpsons(@(x)sin(x.^3),0,2*pi,samplePoints);
end
plot(1:samplePoints,I);
This will give you a plot showing the convergence of the integral vs. the number of samples used for the integration as shown below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/176239/image.png)
0 Commenti
Più risposte (1)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!