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

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

    上一主题 下一主题
    离线fanyushan
     
    发帖
    36
    光币
    52
    光券
    0
    只看楼主 倒序阅读 楼主  发表于: 2010-07-19
    我的M文件如下: &n wg$z{Y  
    function [G5]=fun(x); zq&lxySa  
    syms n1 n2 k1 k2 d; pj6Cvq4bD  
    [subwave,nsub]=textread('subout.txt','%f %f'); Qa+gtGtJ  
    [filmwave,filmtran]=textread('filmtr.dat','%f %f');  =%`"  
    [p,q]=size(subwave); on$a]zx'@  
    for j=1:p; 7\ lb+^$  
        wavel(j)=subwave(j,1); C~*m&,@TT^  
        n(j)=n1+n2/((wavel(j))^2); .}wir,  
        k(j)=k1*exp(k2/wavel(j)); Yn/-m Z  
        N(j)=n(j)-i*k(j); n66 _#X  
        phase(j)=2*pi*N(j)*d/wavel(j); DQ$/0bq   
        ns(j)=nsub(j,1); !T)>q%@ai  
        B(j)=cos(phase(j))+ns(j)*i*sin(phase(j))/N(j); 5**xU+&  
        C(j)=i*N(j)*sin(phase(j))+ns(j)*cos(phase(j)); ~r3g~MCHS  
        T(j)=4*ns(j)/((B(j)+C(j))*conj(B(j)+C(j))); We2=|AB  
        ts(j)=1-((1-ns(j))/(1+ns(j)))^2; I6_+3}Hm{  
        t1(j)=ts(j)*T(j); lVHJ}(<'p  
        tf(j)=filmtran(j,1)/100; w.\:I[  
        difference(j)=(t1(j)-tf(j))^2; ej `$-hBBV  
    end -u{:39y{n  
    G=symsum(difference(j),1,401); ikC;N5Sw  
    G1=subs(G,n1,sym('x(1)')); !RI&FcK  
    G2=subs(G1,n2,sym('x(2)')); $}@l l^  
    G3=subs(G2,k1,sym('x(3)')); c-F&4V  
    G4=subs(G3,k2,sym('x(4)')); %k_JLddlW  
    G5=subs(G4,d,sym('x(5)')); ]Az >W*Y  
    t$J-6dW  
    K""04Ew*pV  
    2#!D"F  
    在matlab下运行 0ro+FJ r  
    >> options=optimset('tolfun',1e-8,'tolx',1e-8); B4C`3@a  
    >> [xmin,value,flag,output]=fminsearch(@fun,[1.7,4000,0.005,400,500],options); 42M3c&@P  
    ;_!;D#:  
    'Tn$lh  
    结果出错如下: Y]PZ| G)  
    }PVB+i M  
    ??? Conversion to double from sym is not possible. 6*E 7}  
    Error in ==> fminsearch at 175 n"JrjvS  
    fv(:,1) = funfcn(x,varargin{:}); VQyDd~Za  
    J{Jxb1:c  
    哪位高手给看看 WG,{:|!E  
     
    分享到
    离线fanyushan
    发帖
    36
    光币
    52
    光券
    0
    只看该作者 1楼 发表于: 2010-07-21
    哪位高人告诉我,错误在哪里呀。M文件复制到命令行,执行,一切正常,就是在求解多元函数0值时,不知道哪里错了。 VH/_0  
    y(HR1v Q;Z  
    C..O_Zn{g  
    万分感谢呀