1
$\begingroup$

I solved a system of equation and get the result Sol

a = 1; b = 2; c = 3; d = 4;
eq1 = {a x + b y*c z - d m};
eq2 = {x y - y z - m m};
eq3 = {10 x - 3 y*c - a};
eq4 = {a m + c y};
eq = Join[eq1, eq2, eq3, eq4];
Sol = {x, y, z, m} /. 
  FindRoot[Thread[eq == 0], {{x, y, z, m}, {0, 0, 0, 0}} // Transpose]

Now, I want to solve this system of equation with the unknown e f g h and get the result SSol. Finally, Minimize[(SSol-Sol).(SSol-Sol),{e f g h}].

e = x1; f = x2; g = x3; h = x4;
eq5 = {e x + f y*g z - h m};
eq6 = {x y - y z - m m};
eq7 = {10 x - 3 y*g - e};
eq8 = {e m + g y};
eqs = Join[eq5, eq6, eq7, eq8]   
SSol = {x, y, z, m} /.FindRoot[Thread[eqs == 0], {{x, y, z, m}, {0, 0, 0, 0}} //Transpose]
Z = (SSol - Sol).(SSol - Sol);
Minimize[Z, {e, f, g, h}]

My code can't work after eqs. Can someone help me fulfill my thought? I really appreciate your help.

enter image description here

$\endgroup$
  • $\begingroup$ Welcome to MSE! What specifically doesn't work? What do you see, and how is this different from what you expect? $\endgroup$ – Victor K. Apr 10 at 0:53
  • $\begingroup$ I want to Minimize[(SSol - Sol).(SSol - Sol), {e, f, g, h}] . Sol is known and SSol is the solution of eqs in which e f g h are what I want to get. $\endgroup$ – YzWu Apr 10 at 1:11
0
$\begingroup$

You can find minimum for all varialbles at once.

Conditions to Minimize take care that you only get variables that are soutions to both equations. Then the lowest minimum of scalar product of equations is zero.

min1 = Minimize[{eq.eqs, Join[Thread[eq == 0], Thread[eqs == 0]]}, {x,
 y, z, m, e, f, g, h}];

min1 // N

(*    {0., {x -> 0.356498, y -> 0.284998, z -> -2.20848, m -> -0.854993, 
            e -> 1., f -> 0.1888, g -> 3., h -> 0.}}   *)

And here the other possible solution for {x,y,z,m} you found with FindRoot.

Minimize[{eq.eqs, Join[Thread[eq == 0], Thread[eqs == 0]], y < 0}, {x,
y, z, m, e, f, g, h}] // N

(*   {0., {x -> 0.0935022, y -> -0.00721976, z -> 0.15848, m -> 0.0216593, 
           e -> 1., f -> 27.2398, g -> 3., h -> 0.}}   *)

Solving for all solutions where minimum zero is reached, shows,h can be choosen free and 2 solutions sets for 0 < h < 4.31696 and only one above.

sol21 = Solve[
    Join[{eq.eqs == 0}, Thread[eq == 0], Thread[eqs == 0], 
Thread[{e, f, g, h} > 0]], {x, y, z, m, e, f, g, h}];

sol21 // N

(*   {{x -> ConditionalExpression[0.0935022, 0. < h < 4.31696], 
y -> ConditionalExpression[-0.00721976, 0. < h < 4.31696], 
z -> ConditionalExpression[0.15848, 0. < h < 4.31696], 
m -> ConditionalExpression[0.0216593, 0. < h < 4.31696], 
e -> ConditionalExpression[1., 0. < h < 4.31696], 
f -> ConditionalExpression[9.71092 (2.80507\[VeryThinSpace]- 0.649778 h), 0. < h < 4.31696], 
g -> ConditionalExpression[3., 0. < h < 4.31696]}, 
{x -> ConditionalExpression[0.356498, h > 0.], 
y -> ConditionalExpression[0.284998, h > 0.], 
z -> ConditionalExpression[-2.20848, h > 0.], 
m -> ConditionalExpression[-0.854993, h > 0.], 
e -> ConditionalExpression[1., h > 0.], 
f -> ConditionalExpression[0.0176532 (10.6949\[VeryThinSpace]+ 25.6498 h), h > 0.], 
g -> ConditionalExpression[3., h > 0.]}}   *)

Plot[Evaluate[{x, y, z, m} /. sol21], {h, 0, 10}, 
  PlotStyle -> {Red, Green, Blue, Magenta}]

enter image description here

Plot[Evaluate[{e, f, g, h} /. sol21], {h, 0, 10}, 
  PlotStyle -> {Red, Green, Blue, Magenta}, PlotRange -> {0, 10}]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ Thank you very much. $\endgroup$ – YzWu Apr 10 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.