Solving an equation with integral with one variable
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Sergio Manzetti
el 10 de Ag. de 2017
Comentada: Star Strider
el 11 de Ag. de 2017
Hi, how can I calculate the following equation involving an integral in matlab?
C + Integral_{-4}_{4} e^(x^2)*x^2 dx = 1
where -4 and 4 are the lower and upper limit, and C is the unknown constant.
Thanks!
0 comentarios
Respuesta aceptada
John BG
el 10 de Ag. de 2017
Editada: John BG
el 11 de Ag. de 2017
Hi Sergio
Since the primitive of
exp(x^2)*x^2
is
Ly=x*exp(x^2)/2-.5*1j*(pi)^.4/2*erf(1j*x)
then the integral in the interval [y1 y2] is
L=Ly2-Ly1
this is
y2=4;
Ly2=y2*exp(y2^2)/2-.5*1j*(pi)^.5*erf(sym(1j*y2))
Ly2 =
149084195602433/8388608 - (erf(4i)*3991211251234741i)/4503599627370496
y1=-4;
Ly1=y1*exp(y1^2)/2-.5*1j*(pi)^.5*erf(sym(1j*y1))
Ly1 =
(erf(4i)*3991211251234741i)/4503599627370496 - 149084195602433/8388608
the value of the integral is
L= Ly2-Ly1
L =
149084195602433/4194304 - (erf(4i)*3991211251234741i)/2251799813685248
way around erf() only working for real inputs
L= double(Ly2-Ly1)
L =
3.7843e+07
therefore
C=1-L
C =
-3.7843e+07
Repeating with
format double
the result is
L =
3.784324335121135e+07
Comment:
When attempting direct integration with command sum
x=[-4:.001:4];L=sum(exp(x.^2) .* x.^2)
L =
3.4537e+10
x=[-4:.00001:4];L=sum(exp(x.^2) .* x.^2)
L =
3.4396e+12
x=[-4:.0000001:4];L=sum(exp(x.^2) .* x.^2)
L =
3.4395e+14
The slopes when approaching -4 and 4 are too sharp for command sum.
Grazie tante per la sua attenzione.
if you find this answer useful would you please be so kind to consider marking my answer as Accepted Answer?
To any other reader, if you find this answer useful please consider clicking on the thumbs-up vote link
thanks in advance
John BG
0 comentarios
Más respuestas (1)
Star Strider
el 10 de Ag. de 2017
Editada: Star Strider
el 10 de Ag. de 2017
If I understand correctly what you want to do, this works:
f = @(x) exp(x.^2) .* x.^2;
Cs = fzero(@(C) C + integral(f, -4, 4) - 1, 1)
Cs =
-3.4395e+07
Or more simply, since ‘C’ is a constant:
C = 1 - integral(f, -4, 4)
C =
-3.4395e+07
If you are using R2011b or earlier, use quad instead of integral:
C = 1 - quad(f, -4, 4)
The result is the same:
C =
-34395040.4474417
here using format long g.
2 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!