MATLAB: Solving an equation with integral with one variable

equationintegral

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!

Best Answer

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