敲代码的蟹老板
2021-07-14 22:23
采纳率: 100%
浏览 20

matlab代码,飞行机的精确定位问题

请问这段代码该如何修改呢?

主函数代码:

y=[1393,375,259,987];
theta=[161.2,45.1,-51];
sigma=[0.8,0.6,1.3];
d4=864.3;
sigma4=2;
x0=[900,700];
nonlcon = @circlecon;
options = optimoptions('fmincon','Display','iter','Algorithm','sqp');
[x,fval]=fmincon('fun',x0,[],[],[],[],[],[],nonlcon,options);



fun函数代码:

f=((atan2(x-x(1),y-y(1))-theta(1))/sigma(1)).^2+...
  ((atan2(x-x(2),y-y(2))-theta(2))/sigma(2)).^2+...
  ((atan2(x-x(3),y-y(3))-theta(3))/sigma(3)).^2+...
  ((d4-sqrt((x-x(4)).^2+(y-y(4)).^2))/sigma4).^2

错误代码:

Failure in initial objective function evaluation. FMINCON cannot continue.

问题描述:

https://blog.csdn.net/qq_29831163/article/details/89389044?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522162626949216780261946844%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fall.%2522%257D&request_id=162626949216780261946844&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2allfirst_rank_v2~rank_v29-2-89389044.first_rank_v2_pc_rank_v29&utm_term=%E9%A3%9E%E6%9C%BA%E7%9A%84%E7%B2%BE%E7%A1%AE%E5%AE%9A%E4%BD%8D%E6%A8%A1%E5%9E%8B&spm=1018.2226.3001.4187

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • CSDN专家-Matlab_Fans 2021-07-14 22:33
    已采纳

    函数定义有问题,fun函数中自变量是什么需要明确,
    y=[1393,375,259,987];
    theta=[161.2,45.1,-51];
    sigma=[0.8,0.6,1.3];
    d4=864.3;
    sigma4=2;
    这些常数都应该写在fun函数中。

    点赞 1 评论

相关推荐 更多相似问题