当前位置:网站首页>matlab fmincon 精度,fmincon与quadprog误差
matlab fmincon 精度,fmincon与quadprog误差
2022-06-29 10:43:00 【全栈程序员站长】
大家好,又见面了,我是你们的朋友全栈君。
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
有没有人能帮我看看这两个程序的运行结果为什么会不一样啊??困扰了好久……
程序一:
%text1.m
clear all;clc;
a = [0.058,0.075,0.092,0.111,0.136,0.092]’;
b = [0.062,0.085,0.128,0.149,0.164,0.148]’;
alpha = [0.054,0.075,0.096,0.123,0.148,0.081]’;
beta = [0.058,0.085,0.112,0.138,0.168,0.101]’;
pk = [0.005,0.005,0.005,0.005]’;
pn = [0,0,0,0,0.005,0.005]’;
qb = [0.008,0.008,0.008,0.008]’;
n = 16;
m = 24;
q = 5;
c0 = -((a’ + b’) / 2 + (beta’ – alpha’) / 4) + pn’;
t = 0.15;
c = t * [c0,-0.01,0.03,pk’,qb’]’
eta1 = beta + b – a;
eta2 = beta + alpha + 2 * (b – a);
bigc0 = (beta * beta’ + alpha * alpha’ + 3 * eta1 * eta2′)/24;
bigc0( : ,7:n) = 0;
bigc0( 7:n , : ) = 0;
bigc = 0.5 * (bigc0 + bigc0′)
A = [-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0;
1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0;0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0;0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0;0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0;
0,0,0,0,0,0,-1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.054,0.075,0.096,0.123,0.148,0.081]’;
beta = [0.058,0.085,0.112,0.138,0.168,0.101]’;
pk = [0.005,0.005,0.005,0.005]’;
pn = [0,0,0,0,0.005,0.005]’;
qb = [0.008,0.008,0.008,0.008]’;
n = 16;
m = 24;
q = 5;
c0 = -((a’ + b’) / 2 + (beta’ – alpha’) / 4) + pn’;
t = 0.15;
c = t * [c0,-0.01,0.03,pk’,qb’]’
eta1 = beta + b – a;
eta2 = beta + alpha + 2 * (b – a);
bigc0 = (beta * beta’ + alpha * alpha’ + 3 * eta1 * eta2′)/24;
bigc0( : ,7:n) = 0;
bigc0( 7:n , : ) = 0
bigc = 0.5 * (bigc0 + bigc0′)
f = c’ * [x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)]’ + 0.5 * [x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)] * bigc * [x(1),x(2),x(3),x(4),x(5),x(6),x(7),x(8),x(9),x(10),x(11),x(12),x(13),x(14),x(15),x(16)]’;
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/132331.html原文链接:https://javaforall.cn
边栏推荐
- Good news | Haitai Fangyuan has passed the cmmi-3 qualification certification, and its R & D capability has been internationally recognized
- Multithreaded high concurrency server: three problems
- (JS) imitate the indexof method to find the position of a character in the string
- 巴比特 | 元宇宙每日必读:HTC 宣布推出首款元宇宙手机,售价约2700元人民币,都有哪些新玩法?...
- CTO专访:合见工软深化产品布局 加速国产EDA技术革新
- QT learning 16 parent-child relationships between QT objects
- Qt学习16 Qt 对象间的父子关系
- Nature | 全球海洋微生物组的生物合成潜力
- 面试高并发,凉了!!(全程高能,建议收藏)
- [NLP] text generation topic 1: basic knowledge
猜你喜欢

影响LED封装散热主要因素有哪些?

Safety innovation practice | Haitai Fangyuan was invited to participate in the technical exchange Seminar on "network information innovation and value co creation in the digital age"

Qt学习10 初探 Qt 中的消息处理

Babbitt | yuancosmos daily must read: HTC announced the launch of the first yuancosmos mobile phone, which costs about 2700 yuan. What are the new ways to play

misc3~7

Exclusive interview with head of suss NIFT: the future of Web3 is inseparable from the governance of "everyone for me, I for everyone"

在日本的 IT 公司工作是怎样一番体验?

Modbus RTU protocol 485 learning 2-way infrared module

Qt学习03 Qt的诞生和本质

what? It's amazing that you can read the whole comic book for free. You can't learn to be a money saver together
随机推荐
【HBZ分享】AQS + CAS +LockSupport 实现ReentrantLock的原理
Follow Me Study HCIE-Big Data-Data Mining 第一章 数据挖掘介绍 模块一
ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)
X-FRAME-OPTIONS web page hijacking vulnerability
rxjs Observable 设计原理背后的 Pull 和 Push 思路
(JS) array de duplication
Take another picture of cloud redis' improvement path
如何识别出轮廓准确的长和宽
Uboot for embedded driver development -- common command parameters in uboot
适合小白的树莓派opencv4.0安装
(JS) array flat
Follow Me Study HCIE-Big Data-Data Mining 第一章 数据挖掘介绍 模块二
又拍雲 Redis 的改進之路
The former security director of Uber faced fraud allegations and concealed the data leakage event
Several types of MySQL index invalidation and their solutions
[HBZ sharing] InnoDB principle of MySQL
Self-Improvement! Junior college "counter attack" master of Zhejiang University, 3 SCI, and finally become a doctor of Tsinghua University!
【高并发】2.8万字的Callable和Future面试知识点总结,看完我直接面进了字节跳动,原谅我有点飘了(上)
Oracle扩充分布式云端服务 为更多客户带来全面公有云服务
(JS) observer mode