Need help in solving coupled equations

1 Ansicht (letzte 30 Tage)
Susan
Susan am 9 Mai 2019
Kommentiert: Susan am 13 Mai 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?
Thanks in advance!
  1 Kommentar
Susan
Susan am 13 Mai 2019
Could someone please help me to solve these coupled equations numerically?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 10 Mai 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
  1 Kommentar
Susan
Susan am 10 Mai 2019
Bearbeitet: madhan ravi am 11 Mai 2019
Thanks for your reply.
Could you please tell me how the equations get solved numerically?
It was my bad to prelocate X,Y,W,Z with zeros. withouth these prelocation, how can I solve the equations?
Thanks

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by