蛊毒传说
求极值:syms x y>> y=x^3+x^2+1>> diff(y)ans =3*x^2 + 2*x>> solve(ans)ans =-2/30极值有两点。求最大值,既求-y的最小值:>> f=@(x)(-x^3-x^2-1)f =@(x)(-x^3-x^2-1)>> x=fminunc(f,-3,3)% 在-3;-3范围内找Warning: Gradient must be provided for trust-region method;using line-search method instead.> In fminunc at 354Optimization terminated: relative infinity-norm of gradient less than options.TolFun.x =-0.6667>> f(x)ans =-1.1481在规定范围内的最大值是1.1481由于函数的局限性,求出的极值可能是局部最小(大)值。求全局最值要用遗传算法。上面简单的函数可以自己估计出来:最大值为inf至于遗传算法,以后提个复杂的问题再回答。