Jump to content

Solving an ODE in Python

NoLoMo
Go to solution Solved by mackncheesiest,

Are you sure your professor doesn't want you to solve it analytically (on paper) and then computationally (i.e. least squares fitting) determine the parameter(s) of the resulting general model that best fits the data? I mean, it's definitely been a while for me, but I don't seem to remember most numerical methods taking sample data as an input.

 

I suppose that if you, say, had 10 samples from t = 0, t = 1, t = 2, ... t = 9 so that you had a data set D = {(0, y0), (1, y1), (2, y2), ..., (9, y9)}, you could just treat that as 10 different problems where you solve the ODE over [0, 1] with an initial condition of (0, y0) and then over [1, 2] with an initial condition of (1, y1), etc... and you place a restriction that if, in your next timestep, you'll touch the edge of an interval (i.e. you're at t = 0.95 with h = 0.05), you force the value to match with (1, y1) so that your solution is continuous.

 

That still doesn't help if you don't have a proper parameter value, however. 

Good evening, I am trying to solve for Newton's Law of Cooling but unsure which method to proceed with. Since I have data my professor wants me to solve using curve fitting but also integrate each step. I might be confusing two entirely different steps in my head but I have been stuck at this point for a while. I have looked up how to solve an ODE using python but not sure how to fit in my data, and with curve fitting I have to have my cooling constant. Don't have any worthwhile code to show yet. just trying to formulate a plan, so a pointer are welcomed. Not sure how to properly ask for help so I will answer anything that I left out to the best of my abilities.

Link to comment
Share on other sites

Link to post
Share on other sites

Guess my question would be, do I start solving for my cooling constant first?

 

Link to comment
Share on other sites

Link to post
Share on other sites

Are you sure your professor doesn't want you to solve it analytically (on paper) and then computationally (i.e. least squares fitting) determine the parameter(s) of the resulting general model that best fits the data? I mean, it's definitely been a while for me, but I don't seem to remember most numerical methods taking sample data as an input.

 

I suppose that if you, say, had 10 samples from t = 0, t = 1, t = 2, ... t = 9 so that you had a data set D = {(0, y0), (1, y1), (2, y2), ..., (9, y9)}, you could just treat that as 10 different problems where you solve the ODE over [0, 1] with an initial condition of (0, y0) and then over [1, 2] with an initial condition of (1, y1), etc... and you place a restriction that if, in your next timestep, you'll touch the edge of an interval (i.e. you're at t = 0.95 with h = 0.05), you force the value to match with (1, y1) so that your solution is continuous.

 

That still doesn't help if you don't have a proper parameter value, however. 

Link to comment
Share on other sites

Link to post
Share on other sites

2 minutes ago, mackncheesiest said:

Are you sure your professor doesn't want you to solve it analytically (on paper) and then computationally (i.e. least squares fitting) determine the parameter(s) of the resulting general model that best fits the data? I mean, it's definitely been a while for me, but I don't seem to remember most numerical methods taking sample data as an input.

 

I suppose that if you, say, had 10 samples from t = 0, t = 1, t = 2, ... t = 9 so that you had a data set D = {(0, y0), (1, y1), (2, y2), ..., (9, y9)}, you could just treat that as 10 different problems where you solve the ODE over [0, 1] with an initial condition of (0, y0) and then over [1, 2] with an initial condition of (1, y1), etc... and you place a restriction that if, in your next timestep, you'll touch the edge of an interval (i.e. you're at t = 0.95 with h = 0.05), you force the value to match with (1, y1) so that your solution is continuous.

 

That still doesn't help if you don't have a proper parameter value, however. 

Yup I spoke to him today, and that's what he wanted.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×