求一元函数的最大值: f(x)=xsin(10πx)+1.0 其中x∈[-1, 2], 求解结果精确到6位小数.(标签-matlab)

求一元函数的最大值:

f(x)=xsin(10πx)+1.0

其中x∈[-1, 2],

求解结果精确到6位小数.用matlab来解

clc,clear,close all;
x=-1:0.000001:2;
f=x.*sin(10*pi.*x)+1;
plot(x,f)
vpa(max(f),7)

img

img

clc,clear,close all;
x=-1:0.000001:2;
f=x.*sin(10*pi.*x)+1;
plot(x,f)
disp(['x=',num2str(x(f==max(f)))])
disp('fmax=')
vpa(max(f),7)

img