Effacer les filtres
Effacer les filtres

Solving an equation with integral with one variable

1 vue (au cours des 30 derniers jours)
Sergio Manzetti
Sergio Manzetti le 10 Août 2017
Commenté : Star Strider le 11 Août 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!

Réponse acceptée

John BG
John BG le 10 Août 2017
Modifié(e) : John BG le 11 Août 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

Plus de réponses (1)

Star Strider
Star Strider le 10 Août 2017
Modifié(e) : Star Strider le 10 Août 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 commentaires
Sergio Manzetti
Sergio Manzetti le 11 Août 2017
Hi Star Strider, I was thinking of something real simple, like on Wolfram Alpha, where you type in "C*integral of f(x) + integral g(x) = 1" . Then you get the output, for the numerical integration of the two integrands, and you get the value of C automatically. Is this feasible in Matlab?
Star Strider
Star Strider le 11 Août 2017
Not to my knowledge.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Mathematics dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by