for loop forward modelling
2 views (last 30 days)
Show older comments
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 Comments
Answers (2)
Sulaymon Eshkabilov
on 30 Mar 2022
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
0 Comments
Torsten
on 30 Mar 2022
Edited: Torsten
on 30 Mar 2022
% 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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!