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

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