## Need help in solving coupled equations

### Susan (view profile)

on 9 May 2019
Latest activity Commented on by Susan

### Susan (view profile)

on 13 May 2019
Hello everybody,
I would like to solve the following equations simultaneously for all X,Y,Z, W where i = 1: Nw, j = 1 : Nl, k = 1: K, W_net1, W_net2, m_net1, and m_net2 are given.
For example for K = 2, Nw = 2, Nl =3, I am looking for all X(1,1), X(2,1),X(1,2), X(2,2), Y(1,1), Y(2, 1), Y(3,1), Y(1,2), Y(2, 2), Y(3,2),.....
The above equations can be implemented in matlab using the following code.
ivec = 1 : Nw;
jvec = 1 : Nl;
X = zeros(Nw, K);
Y = zeros(Nl, K);
W = zeros(Nw, K);
Z = zeros(Nl, K);
S = zeros(Nl, K);
for k = 1 : K
for i = ivec
X(i, k) = 2*(1 - 2*W(i,k))/((1 - 2*W(i,k))*(1 + W_net1(i,k)) + W(i,k)*W_net1(i,k)*(1 - (2*W(i,k))^m_net1(i,k)));
ii = setdiff(ivec, i);
tW1 = prod( 1 - X(ii, k) );
tW2 = prod( 1 - Y(jvec, k) );
W(i,k) = 1 - tW1 * tW2;
end
for j = jvec
Y(j, k) = 2*(1 - 2*Z(j,k))/((1 - 2*Z(j,k))*(1 + W_net2(j,k)) + Z(j,k)*W_net2(j,k)*(1 - (2*Z(j,k))^m_net2(j,k)));
i = ivec;
tZ1 = prod(1 - X(i, k));
jj = setdiff(jvec, j);
tZ2 = prod(1 - Y(jj, k));
tZ3 = tZ2 * tZ1;
Z(j,k) = 1 - tZ3;
S(j,k) = Y(j, k) * tZ3;
end
end
Could someone please tell me how I can solve these equations numerically?

Susan

on 13 May 2019

### Sulaymon Eshkabilov (view profile)

on 10 May 2019

Here is the completed code. Put your data instead of sample data used for W_net1, W_net2, m_net1, m_net2
clc; clearvars
Nw = 2; Nl=3; K=2;
ivec = 1 : Nw;
jvec = 1 : Nl;
W_net1 = randi([-123, 123], Nw, K); % Just sample data generated for demo. You need to use your own data isntead
W_net2 = randi([-123, 123], Nl, K); % Just sample data generated for demo. You need to use use your own data isntead
m_net1 = randi([-123, 123], Nw, K); % Just sample data generated for demo. You need to use use your own data isntead
m_net2 = randi([-123, 123], Nl, K); % Just sample data generated for demo. You need to use use your own data isntead
X = zeros(Nw, K);
Y = zeros(Nl, K);
W = zeros(Nw, K);
Z = zeros(Nl, K);
S = zeros(Nl, K);
for k = 1 : K
for i = ivec
X(i, k) = 2*(1 - 2*W(i,k))/((1 - 2*W(i,k))*(1 + W_net1(i,k)) + W(i,k)*W_net1(i,k)*(1 - (2*W(i,k))^m_net1(i,k)));
ii = setdiff(ivec, i);
tW1 = prod( 1 - X(ii, k) );
tW2 = prod( 1 - Y(jvec, k) );
W(i,k) = 1 - tW1 * tW2;
end
for j = jvec
Y(j, k) = 2*(1 - 2*Z(j,k))/((1 - 2*Z(j,k))*(1 + W_net2(j,k)) + Z(j,k)*W_net2(j,k)*(1 - (2*Z(j,k))^m_net2(j,k)));
i = ivec;
tZ1 = prod(1 - X(i, k));
jj = setdiff(jvec, j);
tZ2 = prod(1 - Y(jj, k));
tZ3 = tZ2 * tZ1;
Z(j,k) = 1 - tZ3;
S(j,k) = Y(j, k) * tZ3;
end
end
X(1,1), X(2,1),X(1,2), X(2,2), Y(1,1), Y(2, 1), Y(3,1), Y(1,2), Y(2, 2), Y(3,2) % Also, you can display other results

Susan

on 10 May 2019