当前位置:网站首页>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
边栏推荐
- (JS) array de duplication
- 5. migrate uboot set default environment variables, crop, and partition
- By asp Net core downloading files according to the path
- How to identify the exact length and width of the contour
- The first "cyborg" in the world died, and he only transformed himself to "change his life against the sky"
- Modbustcp protocol network learning single channel infrared module (double-layer board)
- Modbustcp protocol WiFi wireless learning single channel infrared module (round shell version)
- Qt学习10 初探 Qt 中的消息处理
- 专访 SUSS NiFT 负责人:Web3 的未来离不开“人人为我,我为人人”的治理
- [3 questions per day (2)] minimum operand for generating alternate binary strings
猜你喜欢

Qt学习09 计算器界面代码重构

Encore une fois, le chemin de l'amélioration de redis Cloud

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"

Modbustcp protocol network learning single channel infrared module (medium shell version)

Course design for the end of the semester: product sales management system based on SSM

(JS) filter out keys with value greater than 2 in the object

如何识别出轮廓准确的长和宽

XML外部实体注入漏洞(一)

What are the main factors that affect the heat dissipation of LED packaging?

又拍云 Redis 的改进之路
随机推荐
新版CorelDRAW Technical Suite2022最新详细功能介绍
斐波那锲数列与冒泡排序法在C语言中的用法
Necessary for cloud native development: the first common codeless development platform IVX editor
LeetCode 535 TinyURL的加密与解密[map] HERODING的LeetCode之路
Bs-gx-017 online examination management system based on SSM
Qt学习05 Qt Creator工程介绍
(JS) array flat
What is the experience of working in an IT company in Japan?
How to properly manage temporary files when writing shell scripts
QT learning 09 calculator interface code reconstruction
Qt学习01 GUI程序原理分析
又拍雲 Redis 的改進之路
如何识别出轮廓准确的长和宽
(JS) array methods: slice and slice
Qt学习15 用户界面与业务逻辑的分离
Spark - Task 与 Partition 一一对应与参数详解
美创入选信通院“业务安全推进计划”首批成员单位
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"
misc3~7
【每日3题(2)】生成交替二进制字符串的最少操作数