for loop forward modelling

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 个评论

Not sure what (x_p,y_p,z_p) is.
Can you clarify ?

请先登录,再进行评论。

回答(2 个)

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

类别

帮助中心File 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