In python , generate the following code and calculate the value three different
ID: 3731970 • Letter: I
Question
In python , generate the following code and calculate the value three different ways by hand. !!! 1 Part 1 . Generate random r. y.6yl data points using the following code data = [(x,randon.gauss (1,0.01) *exp(log(2) +10g(id)sx/400) ,20) for x in range(100,201)] where id is your student id. 2. Plot the data 3. The data can be modeled with the following function y=2 You must determine the value of b in three different ways Analitycally, as function of vour student id. ·Using the linear least square fitting function discussed in class. Notice the fitting function above is not linear in b therefore you need to perform a transformation of the data before you can apply linear least squares ·By minimizing 2 using an optimization algorithm (for example New- ton). For each of the above methods: . Explain the method in detail ·Show your steps Show your result . A plot of your fitting function superimposed to the data Do you expect the three methods to agree? Why? If you do not expect them to agree exactely, To what precision should they agree?Explanation / Answer
import sys
# Returns cost of minimum cost path from (0,0) to (m, n) in mat[R][C]
def minCost(cost, m, n):
if (n < 0 or m < 0):
return sys.maxsize
elif (m == 0 and n == 0):
return cost[m][n]
else:
return cost[m][n] + min( minCost(cost, m-1, n-1),
minCost(cost, m-1, n),
minCost(cost, m, n-1) )
#A utility function that returns minimum of 3 integers */
def min(x, y, z):
if (x < y):
return x if (x < z) else z
else:
return y if (y < z) else z
# Driver program to test above functions
cost= [ [1, 2, 3],
[4, 8, 2],
[1, 5, 3] ]
print(minCost(cost, 2, 2))