NDSolve in Mathematica with numerical function
| Add comments > |
|
23 Sep 10
The main reason you are having this error is that, Mathematica tries to solve your equation analytically first. Therefore, it would use symbolic form x for your function, but your function can't handle it. So it is the error. You may try to define your F(x) so that it would only compute if x is a number: F[x_ /; NumberQ[x]] := Module[{}, FindRoot[x y == 1, {y, 1/x}][[1, 2]]];
With this, I can solve the differential equation using NDSolve without any errors. Hope it can help you. |
Please login to post answer.
The problem that I am having is like this(a forward of this post). If I define a numerical function in Mathematica:
F[x_] := Module[{}, FindRoot[ x y == 1, {y, 1/x} ][[1,2]] ];
As you can see that F(x) is just 1/x. However, I just would like to illustrate the point with a simple example.
If I solve a differential equation numerically involving F(x), I would get errors:
sol = NDSolve[{y'[x] == F[x], y[1] == 0}, y[x], {x, 1, 3}];
Errors:
What should I do?