切换到宽版
  • 广告投放
  • 稿件投递
  • 繁體中文
    • 3659阅读
    • 1回复

    [求助]fminsearch应用出错 [复制链接]

    上一主题 下一主题
    离线fanyushan
     
    发帖
    36
    光币
    52
    光券
    0
    只看楼主 倒序阅读 楼主  发表于: 2010-07-19
    我的M文件如下: &W>\Vl1  
    function [G5]=fun(x); 1HO;~NJ]m  
    syms n1 n2 k1 k2 d; S5JM t;O  
    [subwave,nsub]=textread('subout.txt','%f %f'); )Cdw_Yx  
    [filmwave,filmtran]=textread('filmtr.dat','%f %f'); vEx'~_+a9  
    [p,q]=size(subwave); fExFpR,`  
    for j=1:p; Ihf>FMl:  
        wavel(j)=subwave(j,1); J0Yb_(w  
        n(j)=n1+n2/((wavel(j))^2); <7y/)b@  
        k(j)=k1*exp(k2/wavel(j)); gbMA-r:IC  
        N(j)=n(j)-i*k(j); {U-z(0  
        phase(j)=2*pi*N(j)*d/wavel(j); ?*V\ -7jg  
        ns(j)=nsub(j,1); 1V`-D8-?  
        B(j)=cos(phase(j))+ns(j)*i*sin(phase(j))/N(j); B\ 'rxbH  
        C(j)=i*N(j)*sin(phase(j))+ns(j)*cos(phase(j)); d\qszYP[  
        T(j)=4*ns(j)/((B(j)+C(j))*conj(B(j)+C(j))); v^eAQoFLhN  
        ts(j)=1-((1-ns(j))/(1+ns(j)))^2; ;^:8F  
        t1(j)=ts(j)*T(j); GpPM?  
        tf(j)=filmtran(j,1)/100; 6`2i'flv  
        difference(j)=(t1(j)-tf(j))^2; OX.5o lb  
    end yPmo1|'X>d  
    G=symsum(difference(j),1,401); \2u7>fU!  
    G1=subs(G,n1,sym('x(1)')); &</)k|.A6\  
    G2=subs(G1,n2,sym('x(2)')); 1a9' *[  
    G3=subs(G2,k1,sym('x(3)')); -)%\$z  
    G4=subs(G3,k2,sym('x(4)')); Sck!w 3  
    G5=subs(G4,d,sym('x(5)')); Vw ;iE=L  
    1[OY- G  
    C1A  X  
    D*@'%<?  
    在matlab下运行 zji9\  
    >> options=optimset('tolfun',1e-8,'tolx',1e-8); Ip{hg,>  
    >> [xmin,value,flag,output]=fminsearch(@fun,[1.7,4000,0.005,400,500],options); =9,mt K~  
    Q:) 4  
    ExS&fUn `C  
    结果出错如下: 9V)cf  
    |j"C52Q  
    ??? Conversion to double from sym is not possible. )T '?"guh`  
    Error in ==> fminsearch at 175 X%-"b`  
    fv(:,1) = funfcn(x,varargin{:}); TS#1+f]9J<  
    3^Is4H_8  
    哪位高手给看看 G l/3*J  
     
    分享到
    离线fanyushan
    发帖
    36
    光币
    52
    光券
    0
    只看该作者 1楼 发表于: 2010-07-21
    哪位高人告诉我,错误在哪里呀。M文件复制到命令行,执行,一切正常,就是在求解多元函数0值时,不知道哪里错了。 4Tuh]5  
    [)}`w;#  
     k=t{o  
    万分感谢呀