how to Calculate Gravity

5 ビュー (過去 30 日間)
Abubakr Mursi
Abubakr Mursi 2023 年 9 月 26 日
コメント済み: Dyuman Joshi 2023 年 9 月 27 日
A Spherical Cavity Of Radius 8 M Has Its Center 15 M Below The Surface. If The Cavity Is Full Of Water And The Surrounding Rock Has A Density Of 2400kg/M3. Calculate The Gravity Anomaly along the surface with a spacing of 5m
write a matlab script to calculate this anomaly and represents it graphically
clear all
close all
clc
r=8;
z=15;
x=0:10:100;
dp=2400;
G=6.67e-11;
for i=1:100;
g(i)=(G*4*pi*(r^3)*z)/(x^2+z^2)^(3/2);
end
Error using ^
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To operate on each element of the matrix individually, use POWER (.^) for elementwise power.
plot(x,g(i))
could you help me figur out the mistake?

採用された回答

the cyclist
the cyclist 2023 年 9 月 26 日
編集済み: the cyclist 2023 年 9 月 26 日
You are not indexing into x correctly. Here is one way to fix it:
r=8;
z=15;
x=0:10:100;
dp=2400;
G=6.67e-11;
for i=1:numel(x)
g(i)=(G*4*pi*(r^3)*z)/(x(i)^2+z^2)^(3/2);
end
plot(x,g) % I fixed this, too. Plot the whole vector of g
You don't need the for loop, though:
r=8;
z=15;
x=0:10:100;
dp=2400;
G=6.67e-11;
g=(G*4*pi*(r^3)*z)./(x.^2+z^2).^(3/2);
plot(x,g)
  2 件のコメント
Abubakr Mursi
Abubakr Mursi 2023 年 9 月 26 日
thanks deeply
Dyuman Joshi
Dyuman Joshi 2023 年 9 月 27 日
Hello @Abubakr Mursi, if this answer solved your problem, please consider accepting the answer.
Accepting the answer indicates that your problem has been solved (which can be helpful to other people in future) and it awards the volunteer with reputation points for helping you.
You can accept only 1 answer for a question, but you can vote for as many answers as you want. Voting an answer also provides reputation points.

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

その他の回答 (0 件)

カテゴリ

Help Center および File Exchange2-D and 3-D Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by