怎么用MATLAB求二次函数最小值
来源:学生作业帮 编辑:作业帮 分类:综合作业 时间:2024/11/06 01:37:30
怎么用MATLAB求二次函数最小值
我用x=[42.8,42.9,43,43.1,43.2,43.3,43.4,43.5,43.6,43.7,43.8,43.9,44,44.1,44.2,44.3,44.4,44.5,44.6,44.7];
>> y=[23265,23029,22907,22668,22264,22083,22112,22096,21864,21742,21733,21844,21787,21756,21838,21984,21971,21876,21879,21996];
>> p2=ployfit(x,y,2);
求出了
p2 =
1.0e+006 *
0.0009 -0.0821 1.8314
请问下,我要怎么求这个函数的最小值及其横坐标呢?麻烦大虾解决下~
我也试过求函数的对称轴x=-b/2a,x=45.6111.但是我把上面的点输入MATLAB二次拟合的曲线在图像上看着最小点在44°左右,根本不会在45°上面去,其中是什么回事啊?
我用x=[42.8,42.9,43,43.1,43.2,43.3,43.4,43.5,43.6,43.7,43.8,43.9,44,44.1,44.2,44.3,44.4,44.5,44.6,44.7];
>> y=[23265,23029,22907,22668,22264,22083,22112,22096,21864,21742,21733,21844,21787,21756,21838,21984,21971,21876,21879,21996];
>> p2=ployfit(x,y,2);
求出了
p2 =
1.0e+006 *
0.0009 -0.0821 1.8314
请问下,我要怎么求这个函数的最小值及其横坐标呢?麻烦大虾解决下~
我也试过求函数的对称轴x=-b/2a,x=45.6111.但是我把上面的点输入MATLAB二次拟合的曲线在图像上看着最小点在44°左右,根本不会在45°上面去,其中是什么回事啊?
clc;clear
x=[42.8,42.9,43,43.1,43.2,43.3,43.4,43.5,43.6,43.7,43.8,43.9,44,44.1,44.2,44.3,44.4,44.5,44.6,44.7];
y=[23265,23029,22907,22668,22264,22083,22112,22096,21864,21742,21733,21844,21787,21756,21838,21984,21971,21876,21879,21996];
p2=polyfit(x,y,2)
xx=min(x):0.1:max(x);
yy=polyval(p2,x);
Y=vpa(poly2sym(p2,'x'),6)%转化为多项式格式
Y1=diff(Y)%求一阶导数
Xmin=eval(solve(Y1))%一阶导数等于零,极值点
Ymin=polyval(p2,Xmin)
plot(x,y,'o',xx,yy,Xmin,Ymin,'*')
结果:
p2 =
932.1 -82142 1.8314e+006
Y =
932.103*x^2-82142.3*x+.183145e7
Y1 =
1864.206*x-82142.3
Xmin =
44.063
Ymin =
21734
x=[42.8,42.9,43,43.1,43.2,43.3,43.4,43.5,43.6,43.7,43.8,43.9,44,44.1,44.2,44.3,44.4,44.5,44.6,44.7];
y=[23265,23029,22907,22668,22264,22083,22112,22096,21864,21742,21733,21844,21787,21756,21838,21984,21971,21876,21879,21996];
p2=polyfit(x,y,2)
xx=min(x):0.1:max(x);
yy=polyval(p2,x);
Y=vpa(poly2sym(p2,'x'),6)%转化为多项式格式
Y1=diff(Y)%求一阶导数
Xmin=eval(solve(Y1))%一阶导数等于零,极值点
Ymin=polyval(p2,Xmin)
plot(x,y,'o',xx,yy,Xmin,Ymin,'*')
结果:
p2 =
932.1 -82142 1.8314e+006
Y =
932.103*x^2-82142.3*x+.183145e7
Y1 =
1864.206*x-82142.3
Xmin =
44.063
Ymin =
21734