# Reimann sum and numerical integration

18 visualizzazioni (ultimi 30 giorni)
DM il 25 Gen 2015
Commentato: Star Strider il 25 Gen 2015
I am trying to solve the functions below numerically using MATLAB
This is my code where I have used "integral" command to solve for the second integral, while I used Reimann sum to solve for the first. Take for example c=1/128.
x= -1/128:0.0001:1/128;
for j=1:length(x)
den= @(y) pi^2.* sqrt(1- (x(j)+y).^2) .* sqrt(1- y.^2);
fun= @(y) 1./den(y);
ymin= max(-0.999,-0.999-x(j));
ymax= min(0.999,0.999-x(j));
pdfX(j)=integral(fun,ymin,ymax);
end
sum1=0;
for j=1:length(omegat)
func1(j)=pdfX(j)*0.0001;
sum1=sum1+func1(j);
end
F=sum1;
Do you think it is correct? Are there any other ways to make it more accurate?
Thanks
##### 0 CommentiMostra -2 commenti meno recentiNascondi -2 commenti meno recenti

Accedi per commentare.

### Risposta accettata

Star Strider il 25 Gen 2015
I would likely use either trapz or cumtrapz to calculate ‘F’, but otherwise I see no problems.
##### 3 CommentiMostra 1 commento meno recenteNascondi 1 commento meno recente
DM il 25 Gen 2015
Also did you notice I have 0.999 instead of 1, so as to avoid the singularity point, is that OK ?
Star Strider il 25 Gen 2015
Personal preference, really. The trapz function is designed for numerical integration:
F = trapz(x, pdfX)
Avoiding the singularity is likely a good move. I doubt that substituting -0.999 would produce significant error. You might want to experiment with (1-1E-8) instead if you are curious.

Accedi per commentare.

### Categorie

Scopri di più su Numerical Integration and Differentiation in Help Center e File Exchange

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by