subs赋值太慢,大家有遇到没,进来看下啊。
function G=myfun(x) syms x1 x2 x3 x4 t=[5 10 15 20 30 45 60 90 120]; p=[1;2;3;5;10;20;50;100]; i=[1.306 1.036 0.880 0.723 0.564 0.435 0.356 0.262 0.209 1.714 1.356 1.127 0.960 0.749 0.570 0.470 0.357 0.291 1.952 1.544 1.272 1.097 0.856 0.650 0.536 0.413 0.338 2.253 1.780 1.454 1.270 0.992 0.749 0.620 0.483 0.398 2.660 2.101 1.701 1.504 1.177 0.885 0.733 0.579 0.480 3.068 2.422 1.949 1.739 1.361 1.021 0.847 0.674 0.561 3.607 2.846 2.276 2.049 1.605 1.200 0.997 0.800 0.669 4.014 3.166 2.523 2.284 1.789 1.336 1.110 0.896 0.750]; for m=1:8 for n=1:9 F(m,n)=(x1.*(1+x2.*log(p(m,1)))/(t(1,n)+x3).^x4-i(m,n)).^2; end end Q=sum(sum(F)); G=subs(Q,[x1,x2,x3,x4],[x(1),x(2),x(3),x(4)]) 上面是我定义的m函数 [x,fval]=fminsearch ('myfun', [15,1,10,1]) 然后用fminsearch求极小值,发现subs函数赋值太慢,有没有高手帮忙解决下啊 上面的程序可以运行就是很慢。 |