声振论坛

 找回密码
 我要加入

QQ登录

只需一步,快速开始

查看: 1331|回复: 7

[求助]各位前辈,请帮我看一下这个程序,不胜感谢!

[复制链接]
发表于 2006-4-11 08:47 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?我要加入

x
<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 ==&gt; fminunc at 182<br>   f = feval(funfcn{3},x,varargin{:});<br>L = [38.8263, 35.4687, 25.9806, 11.9948,-4.0615, -19.4158, -31.4083, -37.9757,-37.9629, -31.4080,...<br>    -19.4108, -4.0573,11.9961, 25.9829, 35.4653, 38.8230,35.4619, 25.9784, 11.9957, - 4.0606,-19.4149,...<br>    -31.4044, -37.9785, -37.9743,-31.4093, -19.4135, -4.0569, 11.9971,25.9795, 35.4636 ]<br>M = [0.0014, 15.7895, 28.8524, 36.9273,38.6135, 33.6208, 22.8189, 8.0678,-8.0705, -22.8217, -33.6211,...<br>    -38.6107,-36.9260, -28.8503, -15.7902, -0.0005,15.7852, 28.8491, 36.9245, 38.6123,33.6212, 22.8174,...<br>    8.0687, -8.0721,-22.8214, -33.6248, -38.6129, -36.9251,-28.8459, -15.7876 ]<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 [z]=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= [0, 0, 1, 1,38.000 ];<br>[x, fval, exitflag, output ]= fminunc (@myfun2, x0)<br>高手们帮帮忙吧!</P>
[此贴子已经被作者于2006-4-11 9:12:52编辑过]

回复
分享到:

使用道具 举报

 楼主| 发表于 2006-4-11 08:48 | 显示全部楼层
在线期待!!
发表于 2006-4-11 08:50 | 显示全部楼层

回复:(mhl516)[求助]各位前辈,请帮我看一下这个程...

<FONT color=#ff0000>function [z]=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)&gt;rmax<BR>  rmax= r(k)<BR>end<BR>if r(k)&lt;rmin<BR>  rmin=r(k)<BR>end<BR>end<BR>z= rmax-rmin<BR><BR>单独写道一个m文件中去
 楼主| 发表于 2006-4-11 08:51 | 显示全部楼层
我试试看,谢谢啦
 楼主| 发表于 2006-4-11 09:09 | 显示全部楼层
<P>我刚才试了一下,警告又说:??? Undefined command/function 'L'.</P>
<P>Error in ==&gt; 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 ==&gt; fminunc at 182<BR>   f = feval(funfcn{3},x,varargin{:});<BR>好像是我的 L,M,N定义的有问题吧,楼上的 能不能帮我 改一改,先谢过!</P>
发表于 2006-4-11 09:12 | 显示全部楼层

回复:(mhl516)[求助]各位前辈,请帮我看一下这个程...

你没给出L这几个参数,当然了<BR><BR>L = [38.8263, 35.4687, 25.9806, 11.9948,-4.0615, -19.4158, -31.4083, -37.9757,-37.9629, -31.4080,...<BR>    -19.4108, -4.0573,11.9961, 25.9829, 35.4653, 38.8230,35.4619, 25.9784, 11.9957, - 4.0606,-19.4149,...<BR>    -31.4044, -37.9785, -37.9743,-31.4093, -19.4135, -4.0569, 11.9971,25.9795, 35.4636 ]<BR>M = [0.0014, 15.7895, 28.8524, 36.9273,38.6135, 33.6208, 22.8189, 8.0678,-8.0705, -22.8217, -33.6211,...<BR>    -38.6107,-36.9260, -28.8503, -15.7902, -0.0005,15.7852, 28.8491, 36.9245, 38.6123,33.6212, 22.8174,...<BR>    8.0687, -8.0721,-22.8214, -33.6248, -38.6129, -36.9251,-28.8459, -15.7876 ]<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这条语句的下面
 楼主| 发表于 2006-4-11 09:16 | 显示全部楼层
噢,我知道了,谢谢啦[em17]
 楼主| 发表于 2006-4-11 09:18 | 显示全部楼层
我终于做出来了,谢谢楼上的 指导[em17]
您需要登录后才可以回帖 登录 | 我要加入

本版积分规则

QQ|小黑屋|Archiver|手机版|联系我们|声振论坛

GMT+8, 2024-11-25 18:41 , Processed in 0.089648 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表