Working with numerical solutions in mathematica

  • Context: Mathematica 
  • Thread starter Thread starter member 428835
  • Start date Start date
  • Tags Tags
    Mathematica Numerical
Click For Summary

Discussion Overview

The discussion revolves around solving a non-linear ordinary differential equation (ODE) numerically using Mathematica's "NDSolve" command and fitting a polynomial to the resulting solution. Participants explore issues related to data extraction from the numerical solution and integration involving a quadratic function.

Discussion Character

  • Technical explanation
  • Mathematical reasoning
  • Homework-related

Main Points Raised

  • One participant describes successfully solving a non-linear ODE numerically using "NDSolve" but struggles with fitting a polynomial to the solution using the "Fit" command.
  • Another participant suggests that "NDSolve" produces an interpolation function, which can be used to create a table of data points for fitting a polynomial.
  • A participant expresses confusion about integrating the numerical solution alongside a quadratic function, seeking clarification on how to perform this integration correctly.
  • There is mention of an error encountered when attempting to integrate the numerical solution with a constant term included, indicating uncertainty about the integration process.
  • One participant reports receiving multiple outputs from Mathematica when trying to follow the suggested approach, questioning whether they are making an error in their input.

Areas of Agreement / Disagreement

Participants share different approaches to extracting data from the numerical solution and fitting a polynomial, but there is no consensus on the best method or resolution of the integration issues raised. The discussion remains unresolved regarding the integration process and the specific errors encountered.

Contextual Notes

Participants have not fully clarified the assumptions or definitions related to the integration of the numerical solution and the quadratic function, nor have they resolved the errors encountered in Mathematica.

member 428835
Hi PF!

I have just solved a non-linear ODE numerically in mathematica using the "NDSolve" command over a small interval ##[0,1.5]##. I'd like to be able to fit a polynomial to this solution, perhaps using the "Fit" command, although I've had no luck on my own.

Any help is greatly appreciated!
 
Physics news on Phys.org
joshmccraney said:
Hi PF!

I have just solved a non-linear ODE numerically in mathematica using the "NDSolve" command over a small interval ##[0,1.5]##. I'd like to be able to fit a polynomial to this solution, perhaps using the "Fit" command, although I've had no luck on my own.

Any help is greatly appreciated!
Can you give some details of what you have tried?
 
Sure! I typed "data = {NDSolve[{
NDSolve[{y[x] y''[x] + 2 (y'[x])^2 + x y'[x] == 0, y[1] == .00000001,
y'[1] == -1/2}, y, {x, 0, 3/2}]};

Then I typed "parabola = Fit[data,{1,x,x^2},x]"

but I had no luck. I think this is because I am not sure what the NDSolve command is giving me. I can graph it, and it looks simple enough. I just don't know how to deal with it.

Also, when I try to integrate over the NDSolve with respect x there is no problem. However, when I integrate NDSolve with respect to x but include a constant, say something like Ax^2 + Bx + C, I get some sort of error.

Can you help with both of these issues?

Thanks so much fro taking an interest!
 
What NDSolve gives you is an interpolation function, from which you can extract values for different x. The way I found to do what you want, which might not be elegant or the better way to do it with Mathematica, is to first create table of data points, and then work with those points:
Code:
points = Table[{x, Evaluate[y[x] /. data][[1]]}, {x, 0, 1, 0.1}];
parabola = Fit[points, {1, x, x^2}, x]

joshmccraney said:
Also, when I try to integrate over the NDSolve with respect x there is no problem. However, when I integrate NDSolve with respect to x but include a constant, say something like Ax^2 + Bx + C, I get some sort of error.
What is it exactly you want to integrate?
 
  • Like
Likes   Reactions: member 428835
DrClaude said:
What is it exactly you want to integrate?
I want to integrate the numerical solution, call this ##y(x)##, and a quadratic. So I want to do this $$\int_0^1 (y(x)-(Ax^2+Bx+C))\, dx$$
 
And I'm not sure what I'm doing wrong but mathematica is not giving me a solution for the quadratic. After inputting the NDSolve I copied what you posted into mathematica, and it is giving me out 10 responses. Am I doing something wrong here? (Sorry if these are annoying questions, I'm trying to learn mathematica).
 

Similar threads

  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 58 ·
2
Replies
58
Views
7K
  • · Replies 3 ·
Replies
3
Views
8K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
7K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K