I am trying to solve two equations that take the form:

$W_0 \sqrt{1+\left(\dfrac{z}{\lambda\,\pi\, W_{0}^2}\right)}=W_1\;\,\quad \ldots(1)$

$W_0\sqrt{1+\left( \dfrac{z+0.1}{\lambda\, \pi\, W_{0}^2}\right)}=W_2\quad\;\, \ldots(2)$

The quantities $\lambda, W_1, \text{ and } W_2$ are known parameters. I am trying to solve for the unknowns $W_0\text{ and } z$. How would I go about doing this. The result is to be in the $\mathbb{R}$. My attempts are below:

Attempt 1:

Solve[{W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A,W Sqrt[1+((z+0.1)/(\[Lambda] \[Pi]

Attempt 2:

FindInstance[W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A&&W Sqrt[1+((z+0.1)/(\[Lambda] 
\[Pi] W^2))^2]==B,{W,z},Complexes]

Attempt 3:

FindRoot[W Sqrt[1+(z/(\[Lambda] \[Pi] W^2))^2]==A,W Sqrt[1+((z+0.1)/(\[Lambda] \[Pi] 
W^2))^2]==B,{{W,1.03 10^-3},{z,4.0 10^-1}}]

My question is what is the best method to solve equations such as these and what will yield the best numerical or analytical result.

  • 2
    $\begingroup$ If you are trying to do this symbolically, remember to avoid introducing approximate numbers--change 0.1 to 1/10, for example. The result of Solve[{W Sqrt[1 + (z/(λ π W^2))^2] == A, W Sqrt[1 + ((z + 1/10)/(λ π W^2))^2] == B}, {W, z}] // FullSimplify is IMO quite nice. $\endgroup$ Sep 23, 2012 at 0:21
  • 1
    $\begingroup$ If you check your code then W (or W_0 in TeX) comes out to be at the power 4 under square root. In your TeX code it is at the power 2. $\endgroup$ Sep 23, 2012 at 0:39
  • 1
    $\begingroup$ @OleksandrR. I've heard this before: changing 0.1 to 1/10. Why is that? $\endgroup$
    – dearN
    Sep 23, 2012 at 18:15
  • 1
    $\begingroup$ @drN: halirutan's answer explains why. $\endgroup$ Sep 30, 2012 at 23:38

1 Answer 1


All you need is already mentioned in the comment. Let me give you some more information, how you could have prevented your mistake. When I solve something, I almost always try to get an analytic solution first, because then you not only having an answer, but you can investigate under which circumstances your solution is true.

What you have to understand first, that it is crucial in Mathematica, to give problems in the right form: And here I mean, the right form of numeric quantities. You have 3 types of numeric quantities in Mathematica:

  • Analytic (exact) values like 1,100,Exp[2],Pi
  • Machine numbers 1.0, Exp[2.0], N[Pi]
  • Arbitrary-precision numbers 1.0`10, N[Exp[2], 10]

Please read the Numerical Precision carefully to understand the differences. The first thing to know is, that whenever you use exact values only, Mathematica will never do a computation where you lose information. It will only do mathematical correct transformations. See the difference

  Out[17]= -1

Exp[I*Pi + 0.0]
  -1. + 1.22465*10^-16 I

In the last example I forced Mathematica to leave the save field of exact evaluation by using 0.0. This told Mathematica to solve the expression numerically introducing some roundoff error.

And now you know, why you don't want to use 0.1 in your equation. This forces an numeric evaluation which gives you only numeric output instead of analytic.

Therefore, replace the 0.1 by 1/10 and use Solve or Reduce.

 Solve[{W Sqrt[1 + (z/(\[Lambda] \[Pi] W^2))^2] == A, 
   W Sqrt[1 + ((z + 1/10)/(\[Lambda] \[Pi] W^2))^2] == B}, {W, z}]

If you try Reduce, you may have to wait half an hour and you'll get output which takes 10 sheets of paper, but you get conditions which have to hold for an particular solution. Maybe not for this, but for smaller problems this can be very insightful.

Reduce[{W Sqrt[1 + (z/(\[Lambda] \[Pi] W^2))^2] == A, 
  W Sqrt[1 + ((z + 1/10)/(\[Lambda] \[Pi] W^2))^2] == B}, {W, z}, Reals]
  • 3
    $\begingroup$ Great detailed answer on this topic $\endgroup$
    – kale
    Sep 23, 2012 at 3:46
  • 1
    $\begingroup$ Excellent! This was a great response I was looking for, and has also shed some light on me for going about solving equations more efficiently as to the type of solution I want out of it. +1... Thanks. $\endgroup$
    – night owl
    Sep 30, 2012 at 21:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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