how to Calculate Gravity

3 次查看(过去 30 天)
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 个评论
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 CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by