1
$\begingroup$

Basically, all what I want is to use Solve and detect when it can't solve the equation, except for the case when it throws Solve::ifun which will consider as OK and will use the solution returned.

So used Catch on Solve command for this purpose, but now I want to tell Catch to ignore the specific error Solve::ifun.

But Catch does not work this way, instead it wants one to enumerate all the messages that one wants to catch! Which makes it hard to use it the other way around, which is: Please catch everything except this error.

MWE: This gives Solve::ifun

ClearAll[b, a,c]; 
expr = (b*E^(a*c) - a*E^(b*c))/(E^(a*c) - E^(b*c)); 
sol=Check[Solve[0==expr,c],{}];
If[sol==={},
     Print["I can't solve it"],
     Print["Success, solution is ",sol]
]

Mathematica graphics

What I want is to do something like this, which is not valid

sol=Check[Solve[0==expr,c],{}, Except[Solve::ifun]];

Instead, one has to enumerate all possible error messages that one wants to catch! But this list can be very long.

So I need to find all possible messages that Solve throws and remove Solve::ifun from the list? But do not know what all the Solve::* messages are. I searched and so far do not find a place they are listed, and I do not know also if Solve can throw messages that are not Solve:: as well.

It will be better if Catch can be designed to also support Except.

Question Is there an easier way to do what I want than what I showed? Is there a place to find all Solve::* error messages? Can Solve Throw an error which does not start with Solve::

$\endgroup$
2
$\begingroup$

In this case, you combine Check[] and Quiet[]:

Check[Quiet[Solve[(b*E^(a*c) - a*E^(b*c))/
                  (E^(a*c) - E^(b*c)) == 0, c], Solve::ifun], {}]
| improve this answer | |
$\endgroup$
2
$\begingroup$

I would just use the InverseFunctions option of Solve. Compare:

Solve[x Exp[x] == 1, x]

Solve::ifun: Inverse functions are being used by Solve, so some solutions may not be found; use Reduce for complete solution information.

{{x -> ProductLog[1]}}

with:

Solve[x Exp[x] == 1, x, InverseFunctions->True]

{{x -> ProductLog[1]}}

| improve this answer | |
$\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.