Question: Please help with me python homework and modeling question! Coding language: python Question 1: Code to Copy: # 2 - put the ODEs into a
Please help with me python homework and modeling question!
Coding language: python
Question 1:



Code to Copy:
# 2 - put the ODEs into a Python function def Lorenz(current_values, t, sigma, beta, rho): """The famous chaotic Lorenz equations.""" # unpack the variables u, v, .... = current_values ###
# form the derivative we neee to pass back dudt = sigma*(v - u) dvdt = rho*u - v - u*w dwdt = .... ###
# all done, let's gather our results and exit! return [dudt, ...., dwdt] ###
# 3 - choose the initial condition (where to start) u0 = 0 v0 = 1 w0 = 1.05 initial_conditions = np.array([u0, ....]) ###
# 4 - choose time interval over which we want a solution time_max = 60 num_time_points = 4000 time = np.linspace(0, ....) ###
# 5 - choose values for the parameters sigma = 10 beta = 2.667 rho = 26
# 6 - all set! let's get the solution in one line, and unpack it! Lorenz_solution = odeint(Lorenz, initial_conditions, time, args = (sigma, beta, rho))
# unpack so that we can see what we got, using Numpy slicing u_new = Lorenz_solution[:,0] v_new = .... ### w_new = .... ###
# 7 - let's visualize what we got fig = plt.figure(figsize=(20,10)) plt.plot(time, u, label='u') plt.plot(time, ....) ### plt.plot(time, ....) ### plt.grid(alpha=0.2) plt.legend() plt.title('Solution of the Lorenz System') plt.xlabel('time') plt.ylabel('$u, v, w$')
THANK YOU
Many complex systems that you will encounter are chaotic, which means that they have very different behaviors for very small changes in where they start the "initial condition"). The time evolution of chaotic systems is therefore very difficult to predict; a classic example is the weather, which cannot be predicted very well past a few days. In this part of the HW, you will use computational modeling to explore the behavior of a chaotic system The computational model that you will use is in the form of, you guessed it ordinary differential equations (ODES). Back in the 1960s, a scientist named Lorenz wrote down some simple looking equations, which were themselves simplications of a more complete model of the weather. His equations, in the form we like to write them for later use in Python, are A = g(0-u), du de = pu-u-uw, dw dr = - Bw. Our ODE system has three variables u, v, w that evolve with time according to the three parameters op. B. Don't worry about what these variables and parameters actually mean; but, do know that they ultimately came from a more complex model for weather behavior. Believe it or not, these simple-looking ODEs forever changed the way we think about the world! Question 1 (5 points) Most of the code to solve the Lorenz equations is given below. Read through the code figure out how it works and fill in the missing lines so that it works. Look for .... ### - that is where you need to fill in the code that was deleted. Numbers are included in the comments to help you see the pattern that odeint uses. A tutorial of this pattern appears at the bottom of the notebook. If you are still a little confused by odeint, jump to the bottom of this notebook and give that a read! (Note that step 1 was already done by writing the equations in the correct form above.) It is highly advised that you read this before the midterm In [1]: # 2 - put the ones into a Python function def Lorenz(current_values, t, sigma, beta, rho): "The famous chaotic Lorenz equations." # unpack the variables u, V, .... = current values ** # form the derivative we neee to pass back dudt = sigma (v - u) dvdt = rhofu - V - uw dwdt = .... ### # all done, Let's gather our results and exit! return [dudt, ...., dwdt] *** #3 - choose the initial condition where to start) ue = @ VO = 1 WO = 1.05 initial_conditions = np.array([ue, ....]) *** # 4 - Choose time interval over which we want a solution time_max = 60 num_time_points = 4880 time = np.linspace(0, ....) ### # 5 - Choose values for the parameters sigma = 10 beta = 2.667 rho = 26 # 6 - all set! Let's get the solution in one line, and unpack it! Lorenz_solution = odeint(Lorenz, initial_conditions, time, args = (sigma, beta, rho)) # unpack so that we can see what we got, using Numpy slicing u_new = Lorenz_solution[:,] V_new = .... ### w_new = .... ## # 7 - Let's visualize what we got fig = plt.figure(figsize=(20,10)) plt.plot(time, u, label='') plt.plot(time, ....) *** plt.plot(time, ....) *** plt.grid(alpha=0.2) plt.legend() plt.title('Solution of the Lorenz System') plt.xlabel('time') plt.ylabel("$u, v, w$')
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
