Numerical solution in Mathematica

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

The discussion centers on solving a system of ordinary differential equations (ODEs) using Mathematica's NDSolve function. The user encounters issues when defining a function F[x_] that relies on numerical methods, specifically FindRoot, instead of a simple analytical expression. The problem arises because NDSolve attempts to process F[x] symbolically, leading to errors when it encounters non-numeric values. The solution involves ensuring that the function can handle symbolic inputs or restructuring the approach to avoid this conflict.

PREREQUISITES
  • Familiarity with Mathematica 12.0 and its numerical solving capabilities.
  • Understanding of ordinary differential equations (ODEs) and their numerical solutions.
  • Knowledge of the FindRoot function in Mathematica for numerical root-finding.
  • Basic concepts of symbolic versus numerical computation in programming.
NEXT STEPS
  • Explore advanced usage of NDSolve in Mathematica for complex ODE systems.
  • Learn how to define functions that can handle both symbolic and numerical inputs in Mathematica.
  • Investigate alternative numerical methods for solving ODEs, such as using NMinimize or NMaximize.
  • Review best practices for combining symbolic and numerical computations in Mathematica.
USEFUL FOR

Mathematica users, mathematicians, and engineers working on numerical solutions to differential equations, particularly those facing challenges with symbolic and numerical function interactions.

FanOfGR
Messages
2
Reaction score
0
Hello,

I have a problem with numerical solution of the system of ODE's (geodesic eqs.) in Mathematica. The only relevant command I have found is NDSolve. It works perfectly, unless my equations contain functions which are again computed using numerical methods.

Simple example illustrating the problem.
Let's define function

F[x_] := Module[{}, FindRoot[ x y == 1, {y, 1/x} ][[1,2]] ];

I don't want to write F[x_] = 1/x, because I want Mathematica to compute it numerically. This function gives, of course, correct values, e.g. F[2]=0.5.

Now I want to solve equation y' = F with initial condition y(1)=0 using

sol = NDSolve[ {y'[x]== F[x], y[1]==0}, y, {x, 1, 3} ];

If I define F[x_] = 1/x, it works. If I define it by FindRoot, it doesn't. It seems to me that NDSolve tries to work with F[x] in symbolic form, but then FindRoot says, that 1/x is not a number.

I hope that I described the problem clearly. Please, if anybody knows the solution, tell me, I am getting crazy :)

Thank you
 
Physics news on Phys.org
The main problem is that, Mathematica tries to solve your problem analytically first. So it plugs in symbolic x, and your function can't handle it.

Please refer to this question in http://www.voofie.com/concept/Mathematica/" :

http://www.voofie.com/content/163/ndsolve-in-mathematica-with-numerical-function/"

For ways to solve your problem.
 
Last edited by a moderator:

Similar threads

  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 0 ·
Replies
0
Views
1K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K