Mathematica Working with numerical solutions in mathematica

AI Thread Summary
A user successfully solved a non-linear ODE numerically in Mathematica using the "NDSolve" command but struggles to fit a polynomial to the solution with the "Fit" command. They attempted to create a data set from the interpolation function provided by NDSolve but encountered issues when trying to integrate the numerical solution alongside a quadratic expression. The solution involves generating a table of data points from the interpolation function before applying the Fit command. Additionally, the user seeks clarification on integrating the numerical solution with a quadratic, as they receive errors when attempting this. The discussion emphasizes the importance of understanding the output from NDSolve and how to manipulate it for further analysis.
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 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
1
Views
3K
Replies
58
Views
7K
Replies
3
Views
8K
Replies
1
Views
2K
Replies
16
Views
6K
Replies
7
Views
2K
Replies
3
Views
2K
Replies
1
Views
5K
Back
Top