|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
哪位高手帮忙看看
我的M文件是:
function [G5]=fun(x);
syms n1 n2 k1 k2 d;
[subwave,nsub]=textread('subout.txt','%f %f');
[filmwave,filmtran]=textread('filmtr.dat','%f %f');
[p,q]=size(subwave);
for j=1:p;
wavel(j)=subwave(j,1); n(j)=n1+n2/((wavel(j))^2); k(j)=k1*exp(k2/wavel(j)); N(j)=n(j)-i*k(j);
phase(j)=2*pi*N(j)*d/wavel(j); ns(j)=nsub(j,1);
B(j)=cos(phase(j))+ns(j)*i*sin(phase(j))/N(j);C(j)=i*N(j)*sin(phase(j))+ns(j)*cos(phase(j));
T(j)=4*ns(j)/((B(j)+C(j))*conj(B(j)+C(j)));
ts(j)=1-((1-ns(j))/(1+ns(j)))^2;
t1(j)=ts(j)*T(j); tf(j)=filmtran(j,1)/100;
difference(j)=(t1(j)-tf(j))^2;
end
G=symsum(difference(j),1,401); G1=subs(G,n1,sym('x(1)')); G2=subs(G1,n2,sym('x(2)'));
G3=subs(G2,k1,sym('x(3)')); G4=subs(G3,k2,sym('x(4)')); G5=subs(G4,d,sym('x(5)'));
在命令窗口运行
>> options=optimset('tolfun',1e-8,'tolx',1e-8);
>> [xmin,value,flag,output]=fminsearch(@fun,[1.7,4000,0.005,400,500],options);
结果出现如下错误提示
??? Conversion to double from sym is not possible.
Error in ==> fminsearch at 175
fv(:,1) = funfcn(x,varargin{:});
M文件拷贝到命令窗口运行正常,就是用fminsearch是出错,大侠们帮帮忙吧
各位,我都转了好几个论坛了,怎么就没有高手呢?
潜水的高手,冒个泡吧
[ 本帖最后由 ChaChing 于 2010-8-3 08:22 编辑 ] |
|