这是个转载贴子。
Size:=500 X := [25:50:Size] Y := 15 + 0.4 * X + 0.001 * X * X Y := Y + 40 * rand(|Y|) % 随机生成点集 gen_cross_contour_xld (Cross, Size - Y, X, 15, 0.785398) % 将坐标点变成十字架图标。 % 现在将生成的点进行二次曲线拟合:f(x) = a*x^2 + b*x + c 转化为: Ax = B A=[X^2, X, 1], x = [a, b, c] B=f(x) / create_matrix (|X|, 3, 1.0, MatrixA) * 创建|x|行3列,值为1.0的矩阵 create_matrix (|X|, 1, X, MatrixACol1) * 创建|x|行1列,值为x的矩阵,x== [25:50:Size] create_matrix (|X|, 1, X * X, MatrixACol0) * 创建|x|行1列,值为X * X的矩阵 set_sub_matrix (MatrixA, MatrixACol1, 0, 1) *用矩阵MatrixACol1来替换矩阵MatrixA中的0行1列中的值 set_sub_matrix (MatrixA, MatrixACol0, 0, 0) *用矩阵MatrixACol0来替换矩阵MatrixA中的0行0列中的值(这里MatrixA是经过上一步变换之后的矩阵) create_matrix (|X|, 1, Y, MatrixB) solve_matrix (MatrixA, 'general', 0, MatrixB, MatrixX) * 解方程即可得到a,b,c的系数,记为矩阵MatrixX %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% /曲线拟合// Sequence := [0:1200] *该函数是得到矩阵MatrixX中0行0列的值 get_value_matrix (MatrixX, 0, 0, A) get_value_matrix (MatrixX, 1, 0, B) get_value_matrix (MatrixX, 2, 0, C) *得到多项式的值 Distances := A * Sequence * Sequence + B * Sequence + C % 将坐标点变成十字架图标。 gen_contour_polygon_xld (Contour, Size - Distances, Sequence) dev_set_color ('forest green') dev_display (Contour) Message := 'Approximated quadratic function' Message[1] := 'f(x) = ' + A$'.2' + '*x^2 + ' + B$'.2' + '*x + ' + C$'.2' + '' disp_message (WindowHandle, Message, 'window', 100, 25, 'forest green', 'false') disp_end_of_program_message (WindowHandle, 'black', 'true')
转载自:
https://blog.csdn.net/cuhinzozfi/article/details/89414968
本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:


