How Can I Solve This Equation in Mathematica?

  • Context: Mathematica 
  • Thread starter Thread starter Physics_rocks
  • Start date Start date
  • Tags Tags
    Mathematica
Click For Summary
SUMMARY

The discussion focuses on solving the equation e^x = x^3 + x^2 - 0.25 * x - 4 using Mathematica. The user initially attempts to use NSolve with incorrect syntax, specifically using '=' instead of '=='. The correct approach involves defining a function F[x] and using FindRoot for numerical solutions. Additionally, plotting the functions with Plot[{Exp[x], x^3 + x^2 - 0.25*x - 4}, {x, 1, 5}] visually identifies the solutions near x=2 and x=5.

PREREQUISITES
  • Understanding of Mathematica syntax and functions
  • Familiarity with numerical methods in computational mathematics
  • Knowledge of plotting functions in Mathematica
  • Basic algebraic manipulation of equations
NEXT STEPS
  • Learn how to use FindRoot in Mathematica for numerical solutions
  • Explore the Plot function in Mathematica for visualizing equations
  • Study the differences between NSolve and FindRoot in Mathematica
  • Investigate function definitions in Mathematica for better code organization
USEFUL FOR

Mathematica users, students in computational mathematics, and anyone seeking to solve complex equations numerically or graphically.

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
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 11 ·
Replies
11
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K