看来你根本没学过MATLAB。
首先打开matlab窗口
1°在命令行中输入
edit used_for_test
出来一个m编辑窗口,在m文件中,粘贴下面的内容:
function y=used_for_test(x)
I=4000;
L=11.25;
h=x(1);
d=x(2);
temp11=(d^2/4+L^2+h^2)^(3/2);
temp1=2*I*h/temp11;
temp21=(9*d^2/4+L^2+h^2)^(3/2);
temp2=I*h/temp21;
temp31=(L^2+h^2)^(3/2);
temp3=I*h/temp31;
temp41=(d^2+L^2+h^2)^(3/2);
temp4=2*I*h/temp41;
E=temp1+temp2-temp3-temp4;
y=E;
点击保存
2°回到命令窗口,在命令窗口中,输入如下命令:
[X,y]=fmincon(@(x)used_for_test(x),[10;50],[],[],[],[],[8,10,12,100])
便可以得到极小值,
另外,输入如下命令可以得到全局最小值:
[X,y]=fminsearch(@(x)used_for_test(x),[10;50])
temp就是自己随便取的临时变量。
fmincon是求非线性条件极小值的函数
y是最小值,X是取最小值的坐标点。
[10;50]是坐标的初值,【8,10,12,100】是坐标点的取值范围
ezcontourf是画等值线的一个函数
function y=used_for_test(h,d)
I=4000;
L=11.25;
temp11=(d^2/4+L^2+h^2)^(3/2);
temp1=2*I*h/temp11;
temp21=(9*d^2/4+L^2+h^2)^(3/2);
temp2=I*h/temp21;
temp31=(L^2+h^2)^(3/2);
temp3=I*h/temp31;
temp41=(d^2+L^2+h^2)^(3/2);
temp4=2*I*h/temp41;
E=temp1+temp2-temp3-temp4;
y=E;
在命令窗口中直接输入:
ezcontourf(@(h,d)used_for_test(h,d),[8,12,10,100]),colorbar
figure
ezcontourf(@(h,d)used_for_test(h,d),[8,10,80,100]),colorbar
便可直接从图形上看到最小值在边界点(8,100)上