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