11. More Calculus with Python
Activity 11.01: Finding the Minimum of a Surface
Solution:
- We need to import the
random
module to use itsuniform
function, which chooses a random decimal value in a given range:import random from math import sin, cos,sqrt,pi
- Create a function that will provide us with partial derivative of
f
with respect tou
at (v,w
):def partial_d(f,u,v,w,num=10000): """returns the partial derivative of f with respect to u at (v,w)""" delta_u = 1/num try: if u == 'x': return (f(v+delta_u,w) - f(v,w))/delta_u else: return (f(v,w+delta_u) - f(v,w))/delta_u except...