简体   繁体   中英

Matlab Transform old school min find into fminsearch

My code is the following. I was told fminsearch would solve this faster. I checked the docs and tutorials but I'm still in the dark. How would you implement fminsearch here? Thanks in advance.

    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

You need to define your objective function and then use fminsearch . for instance:

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]);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM