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

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

    上一主题 下一主题
    离线fanyushan
     
    发帖
    36
    光币
    52
    光券
    0
    只看楼主 倒序阅读 楼主  发表于: 2010-07-19
    我的M文件如下: o- QG& ]  
    function [G5]=fun(x); lPcVhj6No%  
    syms n1 n2 k1 k2 d; Re,$<9V  
    [subwave,nsub]=textread('subout.txt','%f %f'); ZR-s{2sl  
    [filmwave,filmtran]=textread('filmtr.dat','%f %f'); +V+*7s%fL  
    [p,q]=size(subwave); ZDkD%SCy  
    for j=1:p; CNRU"I+jU  
        wavel(j)=subwave(j,1); "kBqY+:Cn  
        n(j)=n1+n2/((wavel(j))^2); EfBVu  
        k(j)=k1*exp(k2/wavel(j)); : Nj`_2  
        N(j)=n(j)-i*k(j); l88a#zUQDN  
        phase(j)=2*pi*N(j)*d/wavel(j); qzlMn)e  
        ns(j)=nsub(j,1); :CkR4J!m3  
        B(j)=cos(phase(j))+ns(j)*i*sin(phase(j))/N(j); a[74%L?  
        C(j)=i*N(j)*sin(phase(j))+ns(j)*cos(phase(j)); #C,f/PXfaB  
        T(j)=4*ns(j)/((B(j)+C(j))*conj(B(j)+C(j))); jPYe_y  
        ts(j)=1-((1-ns(j))/(1+ns(j)))^2; q4.dLU,1  
        t1(j)=ts(j)*T(j); m~j\?mb{+  
        tf(j)=filmtran(j,1)/100; FH`'1iVH  
        difference(j)=(t1(j)-tf(j))^2; Q(;B)  
    end |N=@E,33  
    G=symsum(difference(j),1,401); r0g/:lJi  
    G1=subs(G,n1,sym('x(1)')); bDFCZH-:'O  
    G2=subs(G1,n2,sym('x(2)')); 4j/iG\  
    G3=subs(G2,k1,sym('x(3)')); ,JQxs7@2k  
    G4=subs(G3,k2,sym('x(4)')); 'Elj"Iiu  
    G5=subs(G4,d,sym('x(5)')); h\u0{!@}  
    ,y8I)+  
    dp[w?AMhM9  
    Zu0;/_rN  
    在matlab下运行 mj(&`HRs4  
    >> options=optimset('tolfun',1e-8,'tolx',1e-8); lR@i`)'?U  
    >> [xmin,value,flag,output]=fminsearch(@fun,[1.7,4000,0.005,400,500],options); ^0s\/qyqm  
    4$?w D <  
    # +QWi0B  
    结果出错如下: -#S)}N En  
    i#]aV]IT  
    ??? Conversion to double from sym is not possible. pe!dm}!h[  
    Error in ==> fminsearch at 175 7dlKdKH  
    fv(:,1) = funfcn(x,varargin{:}); b,rH&+2H  
    `z?KL(rI  
    哪位高手给看看 /[20e1 w!  
     
    分享到
    离线fanyushan
    发帖
    36
    光币
    52
    光券
    0
    只看该作者 1楼 发表于: 2010-07-21
    哪位高人告诉我,错误在哪里呀。M文件复制到命令行,执行,一切正常,就是在求解多元函数0值时,不知道哪里错了。 0~Iu7mPY  
     %K%^ ]{  
    J+}+ "h~.  
    万分感谢呀