Message Boards Message Boards

How to numerically compute an implicit equation?

Posted 11 years ago
Hi, my name is Joaquin, im a mechanical engineering student.  I haven't got any time these months to learn how to use Mathematica even though i'd love to learn it. Im probably gonna take some time on summer to do so. But i have an immediate problem which i hope somebody here can help me.

I need to compute a simple, implicit equation which i cannot solve myself on pen and paper. Newton's method might work but the equation is really nasty! The equation looks like this: C = F(x) + g(x) + h(x). Where F, g, and h are known functions of x, and c a known value. I wasn't able to clear x out. For example: 3 = 4.log(x) + e^x - x^2, really simple and all I have access to a mathematica 9 copy in college. How can i solve it?

PS: please make it step by step, i haven't used the program even once yet! Thanks in advance!
POSTED BY: joaquin mendez
3 Replies
Posted 11 years ago
Thank you both for the help! i was able to compute it after all, and learned a bit about mathematica syntax tangentially haha!This product certainly seems very useful to me, as soon as i can im gonna learn about it so i don't have to bother you guys! 
POSTED BY: joaquin mendez
Bill's answer is nice - I hardly have anything to add - just maybe few things. First of all - it is always a good idea to read and look through examples in documentation - it would take 5 minutes to adopt the to your case. Second - you can do neat things - like monitoring solutions:

f[x_] := -3 + 4 Log[x] + E^x - x^2;
FindRoot[f[x], {x, 6}, EvaluationMonitor :> Print["x = ", x " f(x) = ", f[x]], WorkingPrecision -> 30]



f[x_] := -3 + 4 Log[x] + E^x - x^2;
{res, {stxy}} = Reap@FindRoot[f[x], {x, 6}, StepMonitor :> Sow[{x, f[x]}], WorkingPrecision -> 30];

Plot[-3 + 4 Log[x] + E^x - x^2, {x, 0, 6}, Epilog -> {Red, PointSize[Large], Point[stxy]}]

POSTED BY: Vitaliy Kaurov
Posted 11 years ago
I'm not sure this is what you are looking for. If it isn't then try to explain what I've misunderstood and I'll try again.

First satisfy Mathematica's capitalization and [] versus() requirements and then combine the left and right sides of your equality and plot the result to see where to start looking for the desired x, experiment with plot range until you find an informative plot. But tuck away for the future that Plot isn't necessarily perfect and for really really nasty equations Plot can sometimes give you misleading results or even just a blank page.
In[1]:= Plot[-3 + 4 Log[x] + E^x - x^2, {x, 0, 6}]
Out[1]= ...PlotSnipped...
Then use that information about where the root might lie to help guide FindRoot.
In[2]:= FindRoot[-3+4 Log[x]+E^x-x^2,{x,1.5}]
Out[2]= {x->1.29307}
It is even possible, if you look at the help page for FindRoot and know enough to click on "Details and Options", to discover that you can tell FindRoot the variable to use, the initial value and the upper and lower limits to restrict the search range. That is particularly helpful when you are pretty sure you know where the root should be, but you equation is complicated enough that otherwise FindRoot will get lost wandering further and further away from the root you actually desire. (Bumping that information on how FindRoot up can be used with start, min and max above the "Details and Options" line seems like it would be very helpful because again and again I see new users missing this completely and I didn't realize to look there for long enough that I'm embarrassed.)

The FindRoot method with appropriate information to limit the search, is usually far more successful than trying to use Solve or Reduce with complicated problems.

And if this isn't enough then provide a few more hints, or even everything, about your nasty equation and perhaps someone can find another way to get the solution.
POSTED BY: Bill Simpson
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract