2016-03-03 63 views
1

我的代碼如下。我被告知fminsearch會更快地解決這個問題。我查看了文檔和教程,但我仍然處於黑暗中。你如何在這裏實現fminsearch?提前致謝。Matlab轉換舊派分鐘找到fminsearch

MIN=1e10; 

    up_vec= u_min1+ ku*lambda; 
    vp_vec= v_min1+ kv*lambda; 
    wp_vec= w_min1+ kw*lambda; 

     %%the loop 

    for i_up=1:length(up_vec) 

     for i_vp=1:length(vp_vec) 

      for i_wp=1:length(wp_vec) 

     Jp(i_up,i_vp,i_wp)=norm(p- (A\[up_vec(i_up);vp_vec(i_vp);wp_vec(i_wp)]).* ... 
      [exp(-1i*2*pi/lambda*up_vec(i_up));... 
      exp(-1i*2*pi/lambda*vp_vec(i_vp));... 
      exp(-1i*2*pi/lambda*wp_vec(i_wp))]); 

       if Jp(i_up,i_vp,i_wp) < MIN 

        MIN=Jp(i_up,i_vp,i_wp); 

        ind_umin = i_up; 
        ind_vmin = i_vp; 
        ind_wmin = i_wp; 

        up_vec_min=up_vec; 
        vp_vec_min=vp_vec; 
        wp_vec_min=wp_vec; 

        pp_min=pp; 

       end 

      end 
     end 
    end 

回答

1

您需要定義目標函數,然後使用fminsearch。例如:

funJp = @(u,v,w)(norm(p- (A\[u;v;w]).* ... 
      [exp(-1i*2*pi/lambda*u);... 
      exp(-1i*2*pi/lambda*v);... 
      exp(-1i*2*pi/lambda*w)])); 

x = fminsearch(funJp,[umin_1,vmin_1,wmin_1]);