필터 지우기
필터 지우기

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 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