is there a matlab code for gaussion integration!!!
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
syms x;
syms E;
syms r;
syms D;
syms c;
syms m;
g(x)=exp((-2./h).*(sqrt(2*m*(E-c))).*(sqrt(x*(x+r))-r*log((sqrt(r)+sqrt(x+r))-D)))
채택된 답변
John D'Errico
2018년 10월 26일
편집: John D'Errico
2018년 10월 26일
Did you look on the file exchange? (Clearly not.)
They both look decent, though guassquad is purely a gauss-legendre code, gaussg a more general code for standard weight functions, though it is a guass-kronrod scheme.
In fact, even my sympoly toolbox provides gaussian quadrature rules, thus the weights and nodes for any standard weight function class. So look at the guassquadrule function.
So using guassquadrule from sympoly, the nodes and weights for a 4 point Gauss-Hermite rule would be:
[nodes,weights] = gaussquadrule(4,'hermite')
nodes =
-1.65068012388579 -0.52464762327529 0.52464762327529 1.65068012388579
weights =
0.081312835447245 0.804914090005513 0.804914090005513 0.0813128354472448
To compute the integral of (x^5 - 3*x^2 - 2)*exp(-x.^2), from -inf to inf, I might do:
fun = @(x) (x.^5 -3*x.^2 - 2);
dot(weights,fun(nodes))
ans =
-6.2035884781693
Syms confirms that it was correct:
syms x
int((x.^5 -3*x.^2 - 2)*exp(-x^2),[-inf,inf])
ans =
-(7*pi^(1/2))/2
vpa(ans)
ans =
-6.203588478169306095543586191694
However, will you find a tool that performs gaussian integration for a function that contains symbolic parameters? No, you won't find anything for a good reason. Gaussian integration is a numerical integration procedure, not really designed to do symbolic integration.
Can you use gaussian quadrature for a symbolic function? Well, yes.
So, here a Gauss-Laguerre integral of (a*x*2 + b*x + c)*exp(-x), over the domain [0,inf].
syms a b c
fun = @(x) a*x.^2 + b*x + c;
[nodes,weights] = gaussquadrule(5,'laguerre');
vpa(dot(weights,fun(nodes)),13)
ans =
2.0*a + 1.0*b + 1.0*c
What Gaussian quadrature rule you expect to apply to this function:
g(x)=exp((-2./h).*(sqrt(2*m*(E-c))).*(sqrt(x*(x+r))-r*log((sqrt(r)+sqrt(x+r))-D)))
I have no idea, since I don't see any domain provided, nor do I see any standard weight function in there that can be extracted. So I have a funny feeling that you may be confused as to the purpose and utility of classical Gaussian quadratures.
If you look at Gaussian quadrature rules, they presume a weight function from among several standard forms, AND a domain of integration. Gauss-Legendre assumes a unit weight function, so is applicable to integration of a general function, over the interval [-1,1]. For example, suppose you wanted to compute the integral of cos(exp(x)), over the interval [0,1].
syms x
int(cos(exp(x)),[-1,1])
ans =
cosint(exp(1)) - cosint(exp(-1))
vpa(ans)
ans =
0.67038594208938451613294763492665
Luckily, the symbolic TB is smart enough to do the work, because I'm way too sleepy to think.
Gauss-Legendre presumes an interval of [-1,1], although the nodes and weights can be transformed for other intervals.
fun = @(x) cos(exp(x));
[nodes,weights] = gaussquadrule(15,'legendre');
dot(weights,fun(nodes))
ans =
0.670385942089469
댓글 수: 6
thanks for your attention i give the other variable value and i want to integrate from -inf to inf but i cant get any solution m=.5; E=20; r=2; c=1; h=6.6*10^-34; D=sqrt(r+1)-r*log(1+sqrt(r+1)); g(x)=exp((-2./h).*(sqrt(2*m*(E-c))).*(sqrt(x*(x+r))-r*log((sqrt(r)+sqrt(x+r))-D))) G(x)=int(g(x),[-inf,inf])
answer G(x) =
int(exp(26417569354791965812949041543118848*log((x + 2)^(1/2) + 2^(1/2) + 626122553190977/2251799813685248) - 13208784677395982906474520771559424*(x*(x + 2))^(1/2)), x, -Inf, Inf)
This question, as I thought, has relatively little to do with Gaussian integration, except that sometimes Gaussian integration sometimes allows you to do an integral over an infinite interval.
m=.5;
E=20;
r=2;
c=1;
h=6.6e-34;
D=sqrt(r+1)-r*log(1+sqrt(r+1));
syms x
g = exp((-2./h).*(sqrt(2*m*(E-c))).*(sqrt(x*(x+r))-r*log((sqrt(r)+sqrt(x+r))-D)));
pretty(vpa(g,5))
34 34
exp(2.6418 10 log(sqrt(x + 2.0) + 1.6923) - 1.3209 10 sqrt(x (x + 2.0)))
Your question is how to compute the integral of g, with limits of [-inf,inf].
Again, Gaussian integration has nothing to do with it. Basic mathematics does. The question for you should really be, does that integral exist?
If we look inside the exponential, effectively h(x) = log(g(x)), we would see that as x-->inf
limit(h,inf) approaches -inf
However, the limit of h(x) as x approaches -inf? It goes to:
limit(26417569354791965812949041543118848*log((x + 2)^(1/2) + 2^(1/2) + 626122553190977/2251799813685248) - 13208784677395982906474520771559424*(x*(x + 2))^(1/2),-inf)
ans =
- Inf + pi*13208784677395982906474520771559424i
Your integral is divergent. It has no solution.
thank so so much for your effort .. thats what i want
if i change the interval of interval.. for example from -1 to 1 do you believe that i can get answer!!
CAN you do it then? There are still issues you need to consider.
pretty(vpa(g,5))
34 34
exp(2.6418 10 log(sqrt(x + 2.0) + 1.6923) - 1.3209 10 sqrt(x (x + 2.0)))
We can rewrite this as
g(x) = exp(1.3209e34*H(x))
where H(x) is:
H = @(x) 2*log(sqrt(x+2.0)+1.6923) - sqrt(x.*(x+2.0));
ezplot(H,[-1,1])

Now, you need to recognize that nothing was plotted for negative x. Why not? Because the result is complex for negative x.
H(-.1)
ans =
2.2438 - 0.43589i
Just as bad is the fact that this function is of the general form exp(1.3209e34*H(x)), where H(x) is on the general order of 1.
Do you have any clue how large exp(1.3209e34) is?
By way of comparison, the mass of the sun, measured in grams, is a smaller number.
So, can you compute that integral? Sigh. Does it mean anything?
Aalaa Abu alrob
2018년 11월 12일
편집: Aalaa Abu alrob
2018년 11월 12일
that is a wonderful doctor .. thank so much
what about the integral of g(x) from -1 to 1 ,, how i can do it
can you give me more explanation about it ,,
추가 답변 (1개)
Torsten
2018년 10월 26일
Google "Gaussian Integration & matlab"
카테고리
도움말 센터 및 File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
