Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Solve the following system of ODEs over the interval 0 lessthanorequalto t lesst

ID: 3834504 • Letter: S

Question

Solve the following system of ODEs over the interval 0 lessthanorequalto t lessthanorequalto 10 with 101 evenly spaced points (i.e., np. linspace (0, 10, 101)) using SciPy's odeint function: x' = ax(t) + by (t) + c y' = dx (t) + ey (t) + f with x(0) = 0.0, y (0) = 8.0 a = -10, b = 1, c = 10, d = -5, e = 0.1, and f = 10. You'll notice that odeint returns a 2-D array: name this array sol. The heat diffusion equation can be simplified to the following for a 1-D, steady state with constant generation case: T"(x)+ q/k = 0 where T(x) is the temperature distribution as function of x and q/k is heat generation over conductivity. Define a function, solve_bvp, that will accept the following arguments in the following order: q, k T_0 (value of T(0), T_L (value of T(L), L (length of the 1-D slab of material, i.e., the position at second boundary condition), and N (number of points at which to evaluate the temperature). Your function should return T (a np.array of the temperatures) and x (a np.array of x values at which the temperature is evaluated).

Explanation / Answer

A list in python is data separated by commas in square brackets. Here, we might store the following data in a variable to describe the Antoine coefficients for benzene and the range they are relevant for [Tmin Tmax]. Lists are flexible, you can put anything in them, including other lists. We access the elements of the list by indexing:

Lists are "mutable", which means you can change their values.

2.9.2 tuples

Tuples are immutable; you cannot change their values. This is handy in cases where it is an error to change the value. A tuple is like a list but it is enclosed in parentheses.

2.9.3 struct

Python does not exactly have the same thing as a struct in Matlab. You can achieve something like it by defining an empty class and then defining attributes of the class. You can check if an object has a particular attribute using hasattr.

2.9.4 dictionaries

The analog of the containers.Map in Matlab is the dictionary in python. Dictionaries are enclosed in curly brackets, and are composed of key:value pairs.

2.9.5 Summary

We have examined four data structures in python. Note that none of these types are arrays/vectors with defined mathematical operations. For those, you need to consider numpy.array.

2.10 Indexing vectors and arrays in Python

Matlab post There are times where you have a lot of data in a vector or array and you want to extract a portion of the data for some analysis. For example, maybe you want to plot column 1 vs column 2, or you want the integral of data between x = 4 and x = 6, but your vector covers 0 < x < 10. Indexing is the way to do these things.

A key point to remember is that in python array/vector indices start at 0. Unlike Matlab, which uses parentheses to index a array, we use brackets in python.

We can select a range of elements too. The syntax a:b extracts the a^{th} to (b-1)^{th} elements. The syntax a:b:n starts at a, skips nelements up to the index b.

Suppose we want the part of the vector where x > 2. We could do that by inspection, but there is a better way. We can create a mask of boolean (0 or 1) values that specify whether x > 2 or not, and then use the mask as an index.

You can use this to analyze subsections of data, for example to integrate the function y = sin(x) where x > 2.

2.10.1 2d arrays

In 2d arrays, we use row, column notation. We use a : to indicate all rows or all columns.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote