2
$\begingroup$

How do I solve for coefficients in a nonlinear equation? E.g. Consider $p(x,y,z,t) = e^t(ax^2 + by^2 + cz^2)$ and I seek the values of $a,b,c$ which make $p\approx0$ at all the points $(x=r\cos\theta,y=r\sin\theta,m,t)$ for all $t\ge0$ where $0 < \theta \le 2\pi$. A solution will be $(a,b,c)=\{(m/r)^2,(m/r)^2,-1\}$. General answer =$\{a,a,-ar^2/m^2\}$. How could I have found this sort of answer in Mathematica?

I thought if I can obtain MinValue and MaxValue of p to both be within a small numerical range, then p would be approx zero. So I tried this:

p = Exp[t]*(a*x^2 + b*y^2 + c*z^2);
points = {x->r*Cos[theta],y->r*Sin[theta],z->m};
Minimize[p /. points, 0 < theta <= 2*pi && t >= 0, {a,b,c}]

But Mathematica returns the last line back to me.

I also tried this to no avail, but answers were not found either:

Reduce[p /.points == 0 && 0 < theta <= 2*Pi, {r,theta,t}, Reals]

Last of all I also tried the following but it has been running forever and gives no results:

Solve[ForAll[{r,theta,t}, p /. points == 0 && 0 < theta < 2*Pi], {a,b,c}]
$\endgroup$
1
  • $\begingroup$ No worries, thanks for the help! Here is the actual problem but I was trying to break it down into pieces so I can get help faster. I have tried various methods to deal with this thing mathematica.stackexchange.com/questions/217218 $\endgroup$ – Cogicero Mar 28 '20 at 5:58
2
+50
$\begingroup$

This can be solved by choosing a few arbitrary values of θ:

FullSimplify[
  Solve[0 == E^t (a x^2 + b y^2 + c z^2)
    /. {x -> r Cos[θ], y -> r Sin[θ], z -> m} /. θ -> {0, 1, 2}, {a, b}]]
(* {{a -> -((c m^2)/r^2), b -> -((c m^2)/r^2)}} *)

or

Solve[0 == E^t (a x^2 + b y^2 + c z^2)
  /. {x -> r Cos[θ], y -> r Sin[θ], z -> m}
  /. θ -> RandomReal[{0, 2 π}, 2], {a, b}]
(* {{a -> -((1. c m^2)/r^2), b -> -((1. c m^2)/r^2)}} *)
$\endgroup$
2
$\begingroup$

Firstly, one needs to appreciate that there is no unique solution to the problem at hand, so one cannot ask Mathematica to find the expected answer. At best, it can find the relation between the dependent variables ($a,b,c$ in the simplified example) in terms of independent variables ($r,t,\theta,m$). Fortunately, this is quite doable.

The main function that we will be using is Reduce, which will give all possible cases for which given function is zero. We will then eliminate the possibilities which require independent variables to take specific values (such as $r=0$), as these cases are isolated solutions whereas we are interested in generalized solution. Finally, we will assume that the required inequalities for the solution is satisfied (such as $r\ne0$, which is actually a condition for OP's preferred answer as it involves $a=m^2/r^2$).

The code to do these is as follows:

ClearAll[solve];
Options[solve] = Options[FullSimplify];
solve[independentParameters_List, opts : OptionsPattern[]] := 
  Module[{condition, replace},
   condition[a_, b_] := Table[FreeQ[Equal[a, b], i], {i, 
   Subsets[Alternatives @@ independentParameters, {Length[independentParameters] - 1}]}];
   replace = Equal[a_, b_] :> False /; (Or @@ condition[a, b]);
   FullSimplify[Reduce[# == 0] /. replace /. Unequal[a_, b_] -> True,
   Assumptions -> opts]
  ] &;

We can see it in action as follows:

p[a_, b_, c_][t_, x_, y_, z_] := Exp[t] (a x^2 + b y^2 + c z^2);
p[a, b, c][t, r Sin[\[Theta]], r Cos[\[Theta]], m] // solve[{r, \[Theta], m, t}]
(* a + b Cot[\[Theta]]^2 + (c m^2 Csc[\[Theta]]^2)/r^2 == 0 *)

which gives the general solution:

$$a+b \cot ^2(\theta )+\frac{c m^2 \csc ^2(\theta )}{r^2}=0$$

We can now fix any solution we like; for example, we can get OP's result back as follows:

a + b Cot[\[Theta]]^2 + (c m^2 Csc[\[Theta]]^2)/r^2 == 0 /. {c -> -1, b -> m^2/r^2} // FullSimplify
(* a == m^2/r^2 *)

The code as written is quite general and should work with other input. In particular, we did not make use of anything specific to the function $p(t,x,y,z)$. As an example, consider a similar yet modified function:

p2[a_, b_, c_][t_, x_, y_, z_] := Exp[2 t] (a x^4 + b y^4 + c z^4);
p2[a, b, c][t, r Sin[\[Theta]], r Cos[\[Theta]], m] // solve[{r, \[Theta], m, t}]
(* a + b Cot[\[Theta]]^4 + (c m^4 Csc[\[Theta]]^4)/r^4 == 0 *)

for which fixing $$c=-1\;,b=\frac{m^4}{r^4}$$ gives us the answer $$a=\frac{m^4 \left(\cot ^4(\theta )+\csc ^4(\theta )\right)}{r^4}$$

We can of course use the code for functions with other number of variables. For example:

p3[a_, b_, c_, d_][t_, x_, y_, z_, u_] := Exp[t] (a x^2 + b y^2 + c z^2 + d u^2);
p3[a, b, c, d][t, r Sin[\[Theta]], r Cos[\[Theta]] Sin[\[Phi]], r Cos[\[Theta]] Cos[\[Phi]], m] // solve[{r, \[Theta], \[Phi], m, t}]
(* a + (d m^2 Csc[\[Theta]]^2)/r^2 + Cot[\[Theta]]^2 (c Cos[\[Phi]]^2 + b Sin[\[Phi]]^2) == 0 *)

for which fixing $$b=c=\frac{m^2}{r^2}\;, d=-1$$ fixes $$a=\frac{m^2}{r^2}$$

$\endgroup$

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.