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 Sergiothis is John BG <mailto:jgb2012@sky.com jgb2012@sky.com>Since the primitive of exp(x^2)*x^2isLy=x*exp(x^2)/2-.5*1j*(pi)^.4/2*erf(1j*x)then the integral in the interval [y1 y2] isL=Ly2-Ly1this isy2=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/8388608the value of the integral is L= Ly2-Ly1 L = 149084195602433/4194304 - (erf(4i)*3991211251234741i)/2251799813685248way around erf() only working for real inputsL= double(Ly2-Ly1)L = 3.7843e+07therefore C=1-L C = -3.7843e+07Repeating withformat doublethe result isL = 3.784324335121135e+07Comment: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+14The 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 linkthanks in advanceJohn BG<mailto:jgb2012@sky.com jgb2012@sky.com> Related SolutionsMATLAB: Different results in symbol integration Have found my bug. I have integrated five times.Thanks anyway! MATLAB: Numerical integration of double integral Try thisf1 = @(y1,y2) integral(@(x) x./(1+x.^4/(0.1*y1.^4+1.1*y2.^4)),y2,Inf);f2 = @(y1,y2) exp(-2*pi*f1(y1,y2)) * exp(-pi*y2^2)*y1*y2;f3 = @(x) integral(@(y) f2(x,y), x, inf, 'ArrayValued', 1);result = integral(f3, 0, inf, 'ArrayValued', 1);To extend it to triple integral, just look at how f3 and result statement are related to each other. Related QuestionI have the error message : Subscript indices must either be real positive integers or logicals.How to convert answer to one single numberNumerical Integration in MatlabIssue with solving system of odes in matlab
Best Answer