Need help in solving coupled equations

조회 수: 1 (최근 30일)
Susan
Susan 2019년 5월 9일
댓글: Susan 2019년 5월 13일
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
Susan
Susan 2019년 5월 13일
Could someone please help me to solve these coupled equations numerically?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2019년 5월 10일
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
Susan
Susan 2019년 5월 10일
편집: madhan ravi 2019년 5월 11일
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

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by