How can I solve the italicized equation for the matrix gamma_e, gamma_s and d1 ?

1 view (last 30 days)
What I mean is that, I want to solve the euqation for d1=0.8 for first element in gamma_e and gamma_s and then for d1=0.7 with second element of gamma_e and gamma_s ? I undertsand I have to create an index for the gamma_e and gamma_s matrix, which i am unable to work out.
clc, clear
syms x y d;
dvals = 0.9:-0.1:0.1;
num_d = length(dvals);
EU_e = zeros(num_d,1);
EU_s = zeros(num_d,1);
xvalue1 = zeros(num_d, 1);
yvalue1 = zeros(num_d, 1);
pie2 = zeros(num_d, 1);
for didx = 1 : num_d
d = dvals(didx);
solution = solve( 0.8*(1-y) - (1-d)*x == 0 , x - 0.75*y == 0 , [x y]);
xvalue = double(solution.x);
yvalue = double(solution.y);
%defining pie as pie1
pie1 = (solution.x)*(1-solution.y);
pie1 = double(pie1);
EU_e(didx) = 0.8*(pie1) - (1-d)*xvalue^2/2;
EU_s(didx) = 1- (pie1) - 0.5*(yvalue^2)/2 - 0.5*(yvalue^2 + d)/4;
xvalue1(didx)= double(solution.x);
yvalue1(didx)= double(solution.y);
pie2(didx)= (solution.x)*(1-solution.y);
end
results1 = [EU_e, EU_s];
results2 = [pie2];
results3 = [xvalue1, yvalue1];
results4 = results1(2:9 , :); % dropping the values of EU_e and EU_s for d=0.9.
results5 = results1(1:8, :); % dropping the valuues of EU_e and EU_s for d=0.1.
results6 = [results5 - results4];
theta_e = results6(:,1);
theta_s = results6(:, 2);
mat_e = [0.8; 0.8; 0.8; 0.8; 0.8; 0.8; 0.8; 0.8];
mat_s = ones(8,1);
%I am struck here:
syms d1 u v;
dvals1 = 0.8:-0.1:0.1;
num_d1 = length(dvals1);
gamma_e = zeros(num_d1,1);
gamma_e = zeros(num_d1,1);
gamma_e = theta_e - mat_e;
gamma_s = theta_s+ mat_s;
num_d2 = size(gamma_e);
num_d3 = size(gamma_s);
gamma_e = gamma_e(num_d2, 1);
gamma_s = gamma_s(num_d3, 1);
pie3 = zeros(num_d1, 1);
for didx1 = 1:num_d1
for dide = gamma_e
for dids = gamma_s
d1 = dvals1(didx1);
sol = solve( gamma_e.*(1-v) - (1-d1)*u == 0 , gamma_s.*u - 0.75*v == 0 , [u v]);
xvalue2 = double(sol.u);
yvalue2 = double(sol.v);
pie3 = (sol.u).*(1-sol.v)
pie3 = double(pie3);
end
end
end

Accepted Answer

Torsten
Torsten on 19 Mar 2022
Edited: Torsten on 20 Mar 2022
syms x y d
dvals = 0.9:-0.1:0.1;
num_d = length(dvals);
EU_e = zeros(num_d,1);
EU_s = zeros(num_d,1);
xvalue1 = zeros(num_d, 1);
yvalue1 = zeros(num_d, 1);
EU_e = zeros(num_d,1);
EU_s = zeros(num_d,1);
pie2 = zeros(num_d, 1);
solution = solve( 0.8*(1-y) - (1-d)*x == 0 , x - 0.75*y == 0 , [x y]);
for didx = 1 : num_d
d_N = dvals(didx);
xvalue(didx) = double(subs(solution.x,d,d_N));
yvalue(didx) = double(subs(solution.y,d,d_N));
pie1 = xvalue(didx)*(1-yvalue(didx));
EU_e(didx) = 0.8*pie1 - (1-d_N)*xvalue(didx)^2/2;
EU_s(didx) = 1 - pie1 - 0.5*(yvalue(didx)^2)/2 - 0.5*(yvalue(didx)^2 + d_N)/4;
pie2(didx) = pie1 ;
end
xvalue
yvalue
results1 = [EU_e, EU_s];
results2 = [pie2];
results3 = [xvalue1, yvalue1];
results4 = results1(2:9 , :); % dropping the values of EU_e and EU_s for d=0.9.
results5 = results1(1:8, :); % dropping the valuues of EU_e and EU_s for d=0.1.
results6 = [results5 - results4];
theta_e = results6(:,1);
theta_s = results6(:, 2);
mat_e = [0.8; 0.8; 0.8; 0.8; 0.8; 0.8; 0.8; 0.8];
mat_s = ones(8,1);
%I am struck here:
syms a b d u v
dvals1 = 0.8:-0.1:0.1;
num_d1 = length(dvals1);
gamma_e = zeros(num_d1,1);
gamma_s = zeros(num_d1,1);
gamma_e = theta_e - mat_e;
gamma_s = theta_s + mat_s;
xvalue2 = zeros(num_d1, 1);
yvalue2 = zeros(num_d1, 1);
pie3 = zeros(num_d1,1);
solution = solve([a*(1-v)-(1-d)*u == 0, b*u-0.75*v==0],[u v]);
for didx1 = 1:num_d1
d_N = dvals1(didx1);
gamma_E = gamma_e(didx1);
gamma_S = gamma_s(didx1);
xvalue2(didx1) = double(subs(solution.u,[d,a,b],[d_N,gamma_E,gamma_S]));
yvalue2(didx1) = double(subs(solution.v,[d,a,b],[d_N,gamma_E,gamma_S]));
pie3(didx1) = xvalue2(didx1)*(1-yvalue2(didx1));
end
xvalue2
yvalue2
  3 Comments

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 19 Mar 2022
By a quick glance, one sees that there are a couple of points to be fixed in the 2nd loop, i.e.:
...
for didx1 = 1:num_d1
for dide = 1:numel(gamma_e)
for dids = 1:numel(gamma_s)
d1 = dvals1(didx1);
sol = solve( gamma_e(dide)*(1-v) - (1-d1)*u == 0 , gamma_s(dids)*u - 0.75*v == 0 , [u v]);
xvalue2 = double(sol.u);
yvalue2 = double(sol.v);
pie3 = (sol.u).*(1-sol.v)
pie3 = double(pie3);
end
end
end
  1 Comment
ROHIT SINGH
ROHIT SINGH on 20 Mar 2022
The final matrix of xvalue2 and y value 2 is an 8x8 matrix, I need a 8x1 matrix as in the first loop. That is, in first loop, I solved my set of equations for x and y for given values of 0.8 and 1.0, while in second loop i want them to be solved for d1=0.8 with first element of gamma_e and gamma_s followed by d1=0.7 with second element of gamma_e and gamma_s and so on. I am not inteding to do a cross of identities, that is, i dont want equations in second loop to be solved for, say, d1=0.8 with second element of gamma_e and gamma_s.
can you please help me with this ?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!