Solving an integral with variable as upper limit and plotting the solution
Mostrar comentarios más antiguos
How can I solve an integral when the upper limit is a variable, and then plot the solution? My integral is as follows: Integral of e^(-(y^2))dy and my upper limit is x, while the lower limit is negative infinity. X and y are variables. I have tried using the trapz function, but then you must have a constant as upper limit. I have also tried using the int-funtion, but that is only solving for an indefinite integral. Does anyone know what I should do?
Respuesta aceptada
Más respuestas (4)
Alessandro Masullo
el 20 de En. de 2015
0 votos
You can use cumsum or cumtrapz.
David
el 20 de En. de 2015
0 votos
David
el 20 de En. de 2015
4 comentarios
Torsten
el 21 de En. de 2015
Why don't you use the simple formula I provided ?
Look at the definition of the error function erf(x) in MATLAB ; all your attempts for integration are already implemented in this function.
Best wishes
Torsten.
Alessandro Masullo
el 21 de En. de 2015
upper_limit=upper_limit+0.1;
theta=[-10^5:upper_limit];
y=(pi^(-(0.5)))*exp(-(theta.^2));
z=cumtrapz(theta,y);
David
el 21 de En. de 2015
John D'Errico
el 21 de En. de 2015
You could just use basic calculus.
erf gives you the integral from 0 to x. If you want the integral from -inf to x, then add 1. This is because the integral from -inf to 0 is 1.
erf(-inf)
ans =
-1
(Beware of the order of those limits, which gives me here -1.)
So the integral from -inf to x is
1 + erf(x)
Which is valid for any real x as your upper limit.
David
el 21 de En. de 2015
0 votos
Categorías
Más información sobre Numerical Integration and Differentiation en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!