matlab triple integral conical gravity

8 ビュー (過去 30 日間)
Mia Bodin
Mia Bodin 2014 年 11 月 29 日
コメント済み: Mia Bodin 2014 年 11 月 30 日
Hi everyone,
I'm trying to solve a triple integral in matlab, demonstrating the gravity on a point mass inside a cone. I have solved this byy hand and it works fine with a simple u sub. Does anyone have any ideas why my code isn't working. Thanks!
I've tried:
function F = conical_gravity(r,z,th) % parameters
syms G p r th z h
T = (p*G*r*z)/((r^2+z^2)^(3/2));
F1 = int(T,r,0,z)
F2 = int(F1,z,0,h)
F3 = int(F2,th,0,2*pi)
end
this:
syms G p r z th h a
T = (p*G*r*z)*((r^2+z^2)^(-3/2));
q1 = int(T,r,0,z)
q2 = int(q1,th,0,2*pi)
q3 = int(q2,z,0,h)
and this:
syms th r z h G p
T = (p*G*r*z)*((r^2+z^2)^(-3/2));
int(int(int(T,r,0,z),th,0,2*pi),z,0,h)
along with the previous was using integral3.
Any ideas??
  2 件のコメント
Youssef  Khmou
Youssef Khmou 2014 年 11 月 29 日
is the objective to return symbolic result or numeric one?
Mia Bodin
Mia Bodin 2014 年 11 月 29 日
A symbolic answer, G*p*pi*h*(2-sqrt(2))

サインインしてコメントする。

採用された回答

Mike Hosea
Mike Hosea 2014 年 11 月 29 日
編集済み: Mike Hosea 2014 年 11 月 30 日
Numerical stuff removed since a symbolic answer was needed.
  5 件のコメント
Mike Hosea
Mike Hosea 2014 年 11 月 30 日
編集済み: Mike Hosea 2014 年 11 月 30 日
BTW, I made a mistake before in sorting out the variables when I did the numerical approach. The symbolic approach is, of course, superior in this case, but for your edification, for problems that can't be integrated symbolically, here is what one approach using INTEGRAL3 looks like.
function F = conical_gravity(h,p,G)
% h is a variable.
% p and G are parameters.
T = @(th,z,r)(p.*G.*r.*z) ./ ((r.^2 + z.^2).^(3/2));
Fscalar = @(h)integral3(T,0,2*pi,0,h,0,@(th,z)z);
F = arrayfun(Fscalar,h);
This doesn't work when h=0, unfortunately, because the integrator ends up trying to plug in zeros for both r and z into T.
Mia Bodin
Mia Bodin 2014 年 11 月 30 日
Thank you so much that helped a ton!

サインインしてコメントする。

その他の回答 (2 件)

Youssef  Khmou
Youssef Khmou 2014 年 11 月 29 日
編集済み: Youssef Khmou 2014 年 11 月 29 日
I think that working with symbolic variables will not permit the transformation of integral expressions to numeric type, however if you only want general primitive do not use the bounds :
q1 = int(T,r)
You can proceed as the following, the second integral is based on first, so as the third, in each integral the bold case represents the variable on which we integrate :
G=6.67e-11;
z=2;
p=2;% p=mv
r=4;
T=@(R) (p*G*R*z)/((r^2+z^2)^(3/2));
F1=quad(T,0,z);
the expression of q2 is independent of azimuth theta, you will then multiply q1 by 2pi, try to figure out the solution q3.
  1 件のコメント
Mia Bodin
Mia Bodin 2014 年 11 月 29 日
the only thing is I need to integrate over those bound. Without out doing so I will be unable to obtain the correct answer. You see I'm not trying to get the numerical answer right now, i need the analytic solution, which will be G*p*pi*h*(2-sqrt(2).

サインインしてコメントする。


Roger Stafford
Roger Stafford 2014 年 11 月 30 日
編集済み: Roger Stafford 2014 年 11 月 30 日
I have a very ancient version of the Symbolic Toolbox, but it has trouble with substituting z for (z^2)^(1/2) if you integrate with respect to r first because it doesn't know that z is never negative until too late. Unfortunately you would run into the same kind of trouble if you integrated with respect to z first, because it doesn't know yet that r is never negative. However, I believe later versions will permit you to place constraints on your symbolic variables to avoid this trouble. You might try that.

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by