Mathematica How Can I Solve This Equation in Mathematica?

  • Thread starter Thread starter Physics_rocks
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
The discussion centers on solving the equation e^x = x^3 + x^2 - 0.25x - 4 using Mathematica. The initial attempt with NSolve fails due to incorrect syntax, as it uses "=" instead of "==". It's noted that NSolve is not suitable for non-polynomial equations, and FindRoot should be used instead. A suggestion is made to define the function F[x] = -Exp[x] + x^3 + x^2 - 0.25x - 4 and then apply FindRoot to find solutions. For graphical analysis, using Plot to visualize both sides of the equation is recommended, with the plot indicating two solutions near x=2 and x=5. The importance of selecting appropriate starting points for FindRoot based on the graphical output is emphasized, leading to successful solutions at approximately x=1.
Physics_rocks
Messages
12
Reaction score
0
Hi ,

I'm trying to solve the following equation:
e^x=x^3 + x^2 -1/4* x -4

using this code :
NSolve[Exp[x] = x^3 + x^2 - 0.25 * x - 4, x]

but it doesn't work .

In addition I'm trying to solve it graphically by plotting the left and right functions simultaneously . but how ? with PLOT ?

And when I try with FindRoot , it also says that something is wrong :
FindRoot[Exp[x] == x^3 + x^2 - 0.25 * x - 4, {x, 0}]

can you please help ? thanks
 
Physics news on Phys.org
Physics_rocks said:
Hi ,

I'm trying to solve the following equation:
e^x=x^3 + x^2 -1/4* x -4

using this code :
NSolve[Exp[x] = x^3 + x^2 - 0.25 * x - 4, x]

but it doesn't work .

In addition I'm trying to solve it graphically by plotting the left and right functions simultaneously . but how ? with PLOT ?

And when I try with FindRoot , it also says that something is wrong :
FindRoot[Exp[x] == x^3 + x^2 - 0.25 * x - 4, {x, 0}]

can you please help ? thanks

I don't use mathematica any more but try something like

Code:
F[x_] = - Exp[x] + x^3 + x^2 - 0.25 * x - 4;
NSolve[F[x] == 0,x];
FingRoot[F[x] ==0,{x,0}];
 
Physics_rocks said:
NSolve[Exp[x] = x^3 + x^2 - 0.25 * x - 4, x]
Here there are two problems. First, you need to use == instead of = and second NSolve is for solving polynomials and won't work for your expression. Use FindRoot instead.

Physics_rocks said:
In addition I'm trying to solve it graphically by plotting the left and right functions simultaneously . but how ? with PLOT ?
This is a good approach in general, one I usually use when I cannot easily solve something. Use Plot[{Exp[x], x^3 + x^2 - 0.25*x - 4}, {x, 1, 5}] and you can clearly see that there are two solutions, one near x=2 and one near x=5.

Physics_rocks said:
And when I try with FindRoot , it also says that something is wrong :
FindRoot[Exp[x] == x^3 + x^2 - 0.25 * x - 4, {x, 0}]
Remember, FindRoot is a numerical search that depends on the starting position. If you do the Plot above and know that the intersections are near x=2 and x=5 then use those as your starting points: FindRoot[Exp[x] == x^3 + x^2 - 0.25*x - 4, {x, 2}] gives x->1.98666
FindRoot[Exp[x] == x^3 + x^2 - 0.25*x - 4, {x, 5}] gives x->4.93916
 
Last edited:

Similar threads

  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K