Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

Min/Max/Reflection_point

Views: 99
load("http://omega.albany.edu:8008/Sim.py") #---------------------- # define the funtion which finds its max/min and critical points and inflections. def find0(a,b,f,ep=1e-1,split=1e-2): crit = [] inflecpt = [] n=0 x=a while abs(b-a)>= n: instcrit = [] df2val = df2(x) dfval = df(x) while (sign(df2val)==sign(df2(x))) and abs(b-a)>n: # where df(x) approximately equals to zero it means whether max or mean if abs(df2(x))<ep: instcrit.append(x) n = n+split x = x+split # where df(x) approximately does not equals to zero else: n = n+split x = x+split if instcrit!= [] : crit.append(max(instcrit)) inflecpt.append("Inflection Point") if len(crit)>1: del crit[-1] html.table([(round(crit[x], ndigits=5),inflecpt[x]) for x in [0..len(crit)-1]]) minmax(a,b,f,crit) def minmax(a,b,f,infcrit,ep=1e-1,split=1e-2): crit = [] MmI = [] n=0 x=a count =0 while abs(b-a) >= n: instcrit = [] df2val = df2(x) dfval = df(x) while (sign(dfval)==sign(df(x))) and abs(b-a)>=n: # where df(x) approximately equals to zero it means whether max or mean if abs(df(x))<ep: instcrit.append(x) n = n+split x = x+split # where df(x) approximately does not equals to zero else: n = n+split x = x+split if instcrit!= [] : crit.append(max(instcrit)) if len(crit)>1: del crit[-1] while count<=len(infcrit) and len(crit)!=0: if count==0: if df(crit[count])<0: MmI.append("Local Min point") count = count+1 sn=0 else: MmI.append("Local Max point") count = count+1 sn=1 else: if sn==0: MmI.append("Local Max point") count = count+1 sn=1 else: MmI.append("Local Min point") count = count+1 sn=0 html.table([(round(crit[x], ndigits=5),MmI[x]) for x in [0..len(crit)-1]]) #Start # define a function f(x) = cos(x) df(x) = diff(f,x) df2(x) = diff(df,x) # find0(range,range,function) find0(-10,10,f) print("END")
Using _k = _k_default = 5, TL = TL_all[0:-1] = ['_rr', '_dc', '_ps', '_el', '_sl', '_fs', '_Snj', '_Sdj', '_cb', '_xp', '_sr', '_er', '_es', '_fa', '_pf', '_mrs', '_pmrs']
-7.86Inflection Point
-4.72Inflection Point
-1.58Inflection Point
1.57Inflection Point
4.71Inflection Point
7.85Inflection Point
-9.43Local Min point
-6.29Local Max point
-3.15Local Min point
-0.0Local Max point
3.14Local Min point
6.28Local Max point
9.42Local Min point
END