how to Calculate Gravity

28 vues (au cours des 30 derniers jours)
Abubakr Mursi
Abubakr Mursi le 26 Sep 2023
Commenté : Dyuman Joshi le 27 Sep 2023
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?

Réponse acceptée

the cyclist
the cyclist le 26 Sep 2023
Modifié(e) : the cyclist le 26 Sep 2023
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 commentaires
Abubakr Mursi
Abubakr Mursi le 26 Sep 2023
thanks deeply
Dyuman Joshi
Dyuman Joshi le 27 Sep 2023
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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Function Creation dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by