Skip to main content

Posts

Showing posts from April, 2021

Simple Pushbuttons UI Template for dm-script

 // Pushbutton UI template // // 2021/04/21 // Renfong class UI_Handler : object { number true, false number UIObjectID void SetUIObjectID(object self, number id) { UIObjectID = id }; UI_Handler(object self) { true = 1; false = 0 result("Obect \"UI_Handler\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~UI_Handler(object self) { true = 1; false = 0 result("Obect\"UI_Handler\" ["+self.ScriptObjectGetID()+"] deconstructed. \n") }; void btn1response(object self) { OKdialog("This is a template") }; }; class MainUI : UIFrame { TagGroup btn1 object UI_Handler number true, false, ver MainUI(object self){ true = 1; false = 0; ver=0.1; UI_Handler = alloc(UI_Handler) result("Obect \"MainUI\" ["+self.ScriptObjectGetID()+"] constructed. \n") }; ~MainUI(object self){ result("Obect \"MainUI\" ["+self.Scr...

numpy.polyfit example

 #%% load package import numpy as np import matplotlib.pyplot as plt #%% example 1: simple second order fitting # assume y=2x**2 xx = np.arange(-3,3,step=0.2) yy = 2*xx**2  yy +=  (np.random.random(len(xx))-0.5)  # add noise plt.figure(1, dpi=150) plt.plot(xx, yy, 'ro') # curve fitting lin_fit = np.polyfit(xx, yy, 2) print(lin_fit) x2 = np.arange(-3,3,step=.01) y2 = np.polyval(lin_fit, x2) plt.figure(1) plt.plot(x2,y2, 'k') plt.legend(['raw data','fitting curve']) plt.legend(['raw data','fitting curve']) plt.plot(x2[np.argmin(y2)], np.min(y2), 'b*', markersize=10) plt.text(x2[np.argmin(y2)], np.min(y2)-1,           'min: (%.2f, %.2f)'%(x2[np.argmin(y2)], np.min(y2))) plt.axis([-3,3,-2,20]) plt.show() #================================================= #%% example 2 # assume y-y0 = a*(x-x0)**2 # --> y = ax**2 - 2a*x0*x + a*x0**2 + y0 # let a=-1, x0=1.2, y0=0.7, i.e. the maximum value is located at (1.2, 0.7) # --> y = ...