Question: solve abcd this is for QC QD import numpy as np import matplotlib.pyplot as plt ### Fill in ################################ def f ( x ) :
solve abcd
this is for QC QD
import numpy as np
import matplotlib.pyplot as plt
### Fill in ################################
def fx:
return xxx
def gradientfx:
return #FILL IN
############################################
def plotliveax x y:
axplotx y linestyle: markero markersize color'blue', alpha
printw :f fw:fformatxy
pltpause #this is intentionally added to show the
def gradientdescentwinit, stepsize, niter tolerancee axNone:
w winit
itr
whileitr niter:
if ax:
plotliveax w fw
### FILL IN ###############################
gradient #FILL IN
diff #FILL IN
w #FILL IN
###########################################
stopcriterion npabsdiff
if npallstopcriterion tolerance:
if ax:
plotliveax w fw
printconverged
break
itr
if fwe:
printdiverged
break
return w
if namemain:
fig, ax pltsubplots
wmin
wmax
w nplinspacewmin, wmax,
axplotw fw linestyle color'black'
axsetylabelfw fontsize
axsetxlabelw fontsize
axgrid
axsetxlimnpminw npmaxw
axsetylimnpminfw npmaxfw
gradientdescentwinit stepsize niter tolerancee axax #change winit, stepsize here!
pltshow
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
