[求助]各位前辈,请帮我看一下这个程序,不胜感谢!
<P>这是 一个关于非线性最小值问题。使用的是Matlab7.0。.m 文件如下,警告说??? Error: File: myfun1.m Line: 10 Column: 1<br>Function definitions are not permitted at the prompt or in scripts.</P><P>Error in ==> fminunc at 182<br> f = feval(funfcn{3},x,varargin{:});<br>L = <br>M = <br>N= [ -2.0010, -2.9670, -3.9326, -4.8979,-5.8630, -6.8282, -7.7937, -8.7601,-9.7259, -10.6904, -11.6543,...<br> -12.6209,-13.5862, -14.5507, -15.5175, -16.4838,-17.4502, -18.4149, -19.3811, -20.3463,-21.3115, -22.2779,...<br> -23.2418, -24.2071,-25.1726, -26.1366, -27.1026, -28.0690,-29.0360, -30.0008 ]<br><FONT color=#000000>function =myfun2(x)<br>z= 0;<br>for k= 1:30<br> r(k)=(sqrt((L(k)-x(3)*n(k)-x(1)).^2+(m(k)-x(4)*n(k)-x(2)).^2)-x(5)).^2<br> z= z+r(k)</FONT><br>end<br>z= rmax-rmin<br>调用的优化函数是:x0= ;<br>= fminunc (@myfun2, x0)<br>高手们帮帮忙吧!</P>
[此贴子已经被作者于2006-4-11 9:12:52编辑过]
在线期待!!
回复:(mhl516)[求助]各位前辈,请帮我看一下这个程...
<FONT color=#ff0000>function =myfun1(x)<BR></FONT>rmax= 1000;<BR>rmin= -1000;<BR>for k= 1:30<BR>r(k) = sqrt((L(k) -x(3)*N(k)-x(1)).^2+(M(k)-x(4)*N(k)-x(2)).^2)<BR>if r(k)>rmax<BR> rmax= r(k)<BR>end<BR>if r(k)<rmin<BR> rmin=r(k)<BR>end<BR>end<BR>z= rmax-rmin<BR><BR>单独写道一个m文件中去 我试试看,谢谢啦 <P>我刚才试了一下,警告又说:??? Undefined command/function 'L'.</P><P>Error in ==> myfun2 at 4<BR> r(k)=(sqrt((L(k)-x(3)*n(k)-x(1)).^2+(m(k)-x(4)*n(k)-x(2)).^2)-x(5)).^2</P>
<P>Error in ==> fminunc at 182<BR> f = feval(funfcn{3},x,varargin{:});<BR>好像是我的 L,M,N定义的有问题吧,楼上的 能不能帮我 改一改,先谢过!</P>
回复:(mhl516)[求助]各位前辈,请帮我看一下这个程...
你没给出L这几个参数,当然了<BR><BR>L = <BR>M = <BR>N= [ -2.0010, -2.9670, -3.9326, -4.8979,-5.8630, -6.8282, -7.7937, -8.7601,-9.7259, -10.6904, -11.6543,...<BR> -12.6209,-13.5862, -14.5507, -15.5175, -16.4838,-17.4502, -18.4149, -19.3811, -20.3463,-21.3115, -22.2779,...<BR> -23.2418, -24.2071,-25.1726, -26.1366, -27.1026, -28.0690,-29.0360, -30.0008 ]<BR><BR>放到function这条语句的下面 噢,我知道了,谢谢啦 我终于做出来了,谢谢楼上的 指导
页:
[1]