for loop forward modelling

조회 수: 2 (최근 30일)
Casey Kelly-Weekes
Casey Kelly-Weekes 2022년 3월 30일
편집: Torsten 2022년 3월 30일
Hi there, I am not very good at matlab but need to include this equation in my project, I want to test values of z to see what best fits with the model, but I need to write out the equation first, with sums and loops?
Not sure where to begin other than
% pre-defined constants:
x1 = -100;
x2 = 100;
y1 = -100;
y2 = 100;
G = 6.67E-11; % assign the gravitation constant to G
rho = -2600; % assign the density of surrounding rock to rho
%the equation
Yi_for = zeros(x1,1);
for i = 1:2
for j = 1:2
for k = 1:2
Yi_for(i) =
  댓글 수: 2
Torsten
Torsten 2022년 3월 30일
Not sure what (x_p,y_p,z_p) is.
Can you clarify ?
Casey Kelly-Weekes
Casey Kelly-Weekes 2022년 3월 30일
hi, yes,

댓글을 달려면 로그인하십시오.

답변 (2개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2022년 3월 30일
You can start working somewhat in this way:
...
rho = 2600; % Note density can't be negative.
for ii = 1:2
for jj = 1:2
for k = 1:2
mu(ii,jj,k)=((-1)^ii)*((-1)^jj)*((-1)^k);
dx(ii)=
dy(jj)=
dz(k)=
...
end
end
end

Torsten
Torsten 2022년 3월 30일
편집: Torsten 2022년 3월 30일
% pre-defined constants:
x(1) = -100;
x(2) = 100;
y(1) = -100;
y(2) = 100;
z(1) = -100;
z(2) = -200;
xp = 0;
yp = 0;
zp = 0;
G = 6.67E-11;
delta_rho = 2000;
g_z = 0.0;
for i = 1:2
dxi = x(i) - xp;
for j = 1:2
dyj = y(j) - yp;
for k = 1:2
muijk = (-1)^i * (-1)^j * (-1)^k;
dzk = z(k) - zp;
Rijk = sqrt( dxi^2 + dyj^2 + dzk^2 );
g_z = g_z + ...
muijk * (dzk * atan(dxi * dyj / (dzk * Rijk)) - ...
dxi * log(Rijk + dyj) - ...
dyj * log(Rijk + dxi) );
end
end
end
g_z

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by