Matlab 将 old school min find 转换为 fminsearch

Matlab Transform old school min find into fminsearch

我的代码如下。有人告诉我 fminsearch 会更快地解决这个问题。我检查了文档和教程,但我仍然一头雾水。你将如何在这里实施 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

您需要定义 objective 函数,然后使用 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]);