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 件のコメント
Aalaa Abu alrob
2018 年 10 月 26 日
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.
Aalaa Abu alrob
2018 年 10 月 31 日
thank so so much for your effort .. thats what i want
Aalaa Abu alrob
2018 年 10 月 31 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
