1
$\begingroup$

I am trying to solve the next problem:

Known values are: $e, z, vo, n_p, n_q, s$

Variable to find: $P_2, Q_2, k_r, k_i$

All them are real values. Then I define the next variables as:

$a_1 = ez$

$a_2 = (1-e)z$

$b_1 = n_pP_2+n_qQ_2j$

$b_2 = P_2 + Q_2j$

$c_1 = vo - (k_r+k_ij)(n_pP_2+n_qQ_2j)$

$c_2 = vo - (k_r+k_ij)(P_2+Q_2j)$

where $j$ is the imaginary factor, then I have these two complex equations:

$0 = (a_1 c_2 + a_2 c_1)(b_1/c_1+b_2/c_2) - a_1 a_2(b_1/c_1+b_2/c_2) \overline{(b_1/c_1 + b_2/c_2)} - z*s$ $0 = b_2 - c_2\left( \overline{(c_2-c_1)/z} + e(b_1/c_1+b_2/c_2)\right)$

Pd: the overline means conjugate.

In which the only unknown variables are: $P_2, Q_2, k_r, k_i$

EDIT :

Thanks to @user42582, the formulation of the problem in Mathematica is as follows:

ClearAll["Global`*"]

params = {e, z, v0, np, nq, s};

vars = {P2, Q2, kr, ki};

assums = Element[Join[params, vars], Reals];

rls = {
   a1 -> e z, 
   a2 -> (1 - e) z, 
   b1 -> np P2 + nq Q2 I, 
   b2 -> P2 + Q2 I, 
   c1 -> v0 - (kr + ki I) (np P2 + nq Q2 I), 
   c2 -> v0 - (kr + ki I) (P2 + Q2 I)
 };

eqs = {
   0 == (a1 c2 + a2 c1) (b1/c1 + b2/c2) - a1 a2 (b1/c1 + b2/c2) Conjugate[b1/c1 + b2/c2] - z s, 
   0 == b2 - c2 (Conjugate[(c2 - c1)/z] + e (b1/c1 + b2/c2))
 }/.rls // ComplexExpand;

Reduce[And @@ eqs && assums, vars, Complexes]

However, the code keep running for several minutes without giving a solution. Does Mathematica is able to solve this kind of complex-equation system with symbolic variables? is there other way to tackle the problem?. Any help or suggestion will be appreciated!!

$\endgroup$

closed as off-topic by Daniel Lichtblau, b3m2a1, LCarvalho, Coolwater, LLlAMnYP Dec 12 '17 at 10:39

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question cannot be answered without additional information. Questions on problems in code must describe the specific problem and include valid code to reproduce it. Any data used for programming examples should be embedded in the question or code to generate the (fake) data must be included." – Daniel Lichtblau, b3m2a1, LCarvalho, Coolwater
If this question can be reworded to fit the rules in the help center, please edit the question.

  • $\begingroup$ welcome; you are supposed to provide some code for replication purposes and troubleshooting; if you are having trouble formulating your problem in WL I'd suggest looking at the following built-in functions/symbols: List, Set, Rule, ReplaceAll, Element, ... $\endgroup$ – user42582 Dec 7 '17 at 18:52
  • $\begingroup$ ... Conjugate, Imaginary, Solve, probably Reduce and ComplexExpand. $\endgroup$ – user42582 Dec 7 '17 at 18:53
  • $\begingroup$ You cannot solve for four variables with only two equations. Presumably, your known values includes s. Start with $Assumptions = Element[{e, ki, kr, np, nq, P2, Q2, s, v0, z}, Reals]; and then any function that uses the option Assumptions (e.g., Simplify, Solve, Reduce) will assume that the variables are real. $\endgroup$ – Bob Hanlon Dec 7 '17 at 19:19
  • $\begingroup$ @BobHanlon if you did not notice, two complex equations give 4 real equations and with 4 variables, it can be solved. $\endgroup$ – Bur Nor Dec 7 '17 at 23:10
  • $\begingroup$ @user42582 I am ashamed to say that I dont even know how to code it using Mathematica, if someone could give me a hand on that, really be thankful I just download that app to solve this equation, only for that. $\endgroup$ – Bur Nor Dec 7 '17 at 23:11
3
$\begingroup$

Let params denote a list that collects all the parameters (known values) of the problem ie params = {e, z, v0, np, nq, P1, Q1}.

Also, let vars bundle together all the variables of the problem vars = {P2, Q2, kr, ki}.

Notice that we are not going to use sub-scripted variables (eg we use P2 instead of $P_2$).

It is not impossible to use sub-scripted variables with Mathematica / WL (eg expressions like Subscript[P,2]), in fact it is relatively straightforward to use them, but we are going to take the relatively safe and fast route (please note this is a subjective judgement about what's 'safe' and 'fast'; other users might have different opinions on the matter).

After having defined our parameters and our variables, the next thing we need to do is, to define a list of rules that we are going to use, in order to replace the quantities in the equations, with their respective definitions (see below)

rls = {
   a1 -> e z, 
   a2 -> (1 - e) z, 
   b1 -> np P2 + nq Q2 I, 
   b2 -> P2 + Q2 I, 
   c1 -> v0 - (kr + ki I) (np P2 + nq Q2 I), 
   c2 -> v0 - (kr + ki I) (P2 + Q2 I)
 };

rls is a symbol that contains a list of rules.

Rule replacement is a central theme in Mathematica / WL (perhaps, this might be helpful, also please check the relevant links in the comment section of the question).

Effectively, when you pair a replacing rule like eg x->1 with an expression that contains the symbol x, you can replace all the instances of x in the expression with 1, eg evaluating

ReplaceAll[x^2+x+1, x->1]

or

x^2+x+1/.x->1

should return 3 ( = 1^2+1+1).

Note how /. is the infix notation for ReplaceAll (in a similar fashion, it is possible to write addition 'traditionally' 1+1 but also like a function Plus[1,1]).

Using rules in the context of the question, is useful in order to transform the equations, from relations that contain the composite quantities $a_1,a_2,b_1,b_2,c_1,c_2$, to relations that contain the parameters params (and variables, vars) of the problem.

eqs = {
   0 == (a1 c2 + a2 c1) (b1/c1 + b2/c2) - a1 a2 (b1/c1 + b2/c2) Conjugate[b1/c1 + b2/c2] - z s, 
   0 == b2 - c2 (Conjugate[(c2 - c1)/z] + e (b1/c1 + b2/c2))
 }/.rls // ComplexExpand;

Evaluating this code will return a long expression that is not replicated here (for the use of ComplexExpand, please see here; also // is the postfix way of applying functions, please see Postfix).

After having reached thus far, the next step is to use one of the built-in functions available to Mathematica / WL in order to solve the system of equations.

Unfortunately, evaluating

Reduce[And @@ eqs && assums, vars, Complexes]

or

Solve[And @@ eqs && assums, vars, Complexes]

(where assums = Element[Join[params, vars], Reals]) takes a long time to terminate on my system (I had to abort evaluation);

Therefore, the answer to the first question (whether Mathematica can 'solve such equations?') is uncertain at this point. Perhaps other users can evaluate the relevant expressions and provide more decisive answers.

As far as the other part of the question is concerned ('could you please give some guide so that I can apply to my system of equations.'), this answer was a attempt at a (really) fast introduction to the relevant syntax and practical application of the appropriate functions needed to tackle the question in hand.


code section for replication purposes

params = {e, z, v0, np, nq, P1, Q1};

vars = {P2, Q2, kr, ki};

assums = Element[Join[params, vars], Reals];

rls = {
   a1 -> e z, 
   a2 -> (1 - e) z, 
   b1 -> np P2 + nq Q2 I, 
   b2 -> P2 + Q2 I, 
   c1 -> v0 - (kr + ki I) (np P2 + nq Q2 I), 
   c2 -> v0 - (kr + ki I) (P2 + Q2 I)
 };

eqs = {
   0 == (a1 c2 + a2 c1) (b1/c1 + b2/c2) - a1 a2 (b1/c1 + b2/c2) Conjugate[b1/c1 + b2/c2] - z s, 
   0 == b2 - c2 (Conjugate[(c2 - c1)/z] + e (b1/c1 + b2/c2))
 }/.rls // ComplexExpand;

Reduce[And @@ eqs && assums, vars, Complexes]

or

Solve[And @@ eqs && assums, vars, Complexes]
$\endgroup$
  • $\begingroup$ Thank you very much for you good explanation, it is very useful, many thanks!! I manage to run the code you provided, but changing -> to = inside the list of rules ( rls ). However, I dont get the solution (values of kr, ki, P2, Q2) but this function link $\endgroup$ – Bur Nor Dec 8 '17 at 14:21
  • $\begingroup$ One quest I have is if with complexes you are telling the algorithm that the equations have complex nature, so that internally it can separate real and imaginary components and equal each one to zero in each of the two equations. @user42582 $\endgroup$ – Bur Nor Dec 8 '17 at 14:28
  • $\begingroup$ I think that Solve returns unevaluated because when you replaced -> with = you effectively replaced $a_1,a_2,b_1,b_2,c_1,c_2$ with their definitions and that messed with assums; try evaluating the code without any modifications and if it's taking too long to finish hold Alt and press . to abort. $\endgroup$ – user42582 Dec 8 '17 at 14:30
  • $\begingroup$ specifying the domain in eg Solveinstructs the function to 'solve for real values of variables, but function values are allowed to be complex' (from the documentation of Solve) $\endgroup$ – user42582 Dec 8 '17 at 14:33
  • $\begingroup$ Another issues is that it seems that the complexity of the problem is a bit much for the software? Do you think it would help if real and imaginary part of these two equations are explicitly separated? How would it be the code structure for that?, I appreciate your support!! @user42582 $\endgroup$ – Bur Nor Dec 8 '17 at 15:22
2
$\begingroup$

Continuing the answer of @user42582. You have to use numeric values for the parameters, because there are too much of them to give a general solution with Reduce.

In order to get 4 equations for 4 variables, do ComplexExpand

ceRe1 = ComplexExpand[
Re[(a1 c2 + a2 c1) (b1/c1 + b2/c2) - 
   a1 a2 (b1/c1 + b2/c2) Conjugate[b1/c1 + b2/c2] - z s /. rls], 
TargetFunctions -> {Re, Im}] // Together;

ceIm1 = ComplexExpand[
Im[(a1 c2 + a2 c1) (b1/c1 + b2/c2) - 
   a1 a2 (b1/c1 + b2/c2) Conjugate[b1/c1 + b2/c2] - z s /. rls], 
TargetFunctions -> {Re, Im}] // Together;

ceRe2 = ComplexExpand[
Re[b2 - c2 (Conjugate[(c2 - c1)/z] + e (b1/c1 + b2/c2)) /. rls], 
TargetFunctions -> {Re, Im}] // Together;

ceIm2 = ComplexExpand[
Im[b2 - c2 (Conjugate[(c2 - c1)/z] + e (b1/c1 + b2/c2)) /. rls], 
TargetFunctions -> {Re, Im}] // Together;

equ[e_, z_, v0_, np_, nq_, P1_, Q1_, s_] = {ceRe1 == 0, ceIm1 == 0, 
    ceRe2 == 0, ceIm2 == 0};

With definite parameters equ[e, z, v0, np, nq, P1, Q1, s], lets do numerical solution. It is faster, to look also for complex solutions and later select the real ones.

Select[vars /.NSolve[Rationalize[equ[3, 4, 5, -1, -5, -2, -7, 1], 0], vars, 
    WorkingPrecision -> 25], # \[Element] Reals &]

(*    {{-242.5520609774053748529452, 0, -0.2020193436400476926216504, 
         0}, {-4.594775269939857887725161, 0, -0.1417971758148797823998203, 
         0}}    *)
$\endgroup$
  • $\begingroup$ Thanks for you help @Akku14, but I need the system to be solve in the symbolic form, because I want to know the influence of the variables e, z, v0, np, nq, s over kr , ki. Do you think Mathematica is able to solve this sytem with symbolic variables? can you advice me please. $\endgroup$ – Bur Nor Dec 9 '17 at 15:36

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