Azzera filtri
Azzera filtri

how to Calculate Gravity

5 visualizzazioni (ultimi 30 giorni)
Abubakr Mursi
Abubakr Mursi il 26 Set 2023
Commentato: Dyuman Joshi il 27 Set 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?

Risposta accettata

the cyclist
the cyclist il 26 Set 2023
Modificato: the cyclist il 26 Set 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 Commenti
Abubakr Mursi
Abubakr Mursi il 26 Set 2023
thanks deeply
Dyuman Joshi
Dyuman Joshi il 27 Set 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by