Matlab拟合函数求解导数为零的点的坐标x=8:18;y=[8 8 8 9 10 11 11 9 9 8 8];想对它做4次多项拟合,然后对拟合好的函数求解一阶导和二阶导为零的点的坐标

问题描述:

Matlab拟合函数求解导数为零的点的坐标
x=8:18;
y=[8 8 8 9 10 11 11 9 9 8 8];
想对它做4次多项拟合,然后对拟合好的函数求解一阶导和二阶导为零的点的坐标

程序如下:
clear
clc
x=8:18;
y=[8 8 8 9 10 11 11 9 9 8 8];
b = polyfit(x,y,4) %%%%%% 4阶拟合
y = poly2sym(b);
dy = diff(y,'x');
x0 = real(double(solve(dy)))
ddy = diff(dy,'x');
xx0 = double(solve(ddy))
结果如下:
b =
0.0087 -0.4615 8.8153 -71.8543 219.3217
x0 =
17.4748
8.8760
13.2493
xx0 =
15.6824
10.7176
copyright(c) cxd1301