当前位置:网站首页>Matlab fmincon precision, fmincon and quadprog error
Matlab fmincon precision, fmincon and quadprog error
2022-06-29 13:49:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
The suspected violation of this floor has been folded by the system Hide this building view this building
Can someone help me see why the running results of these two programs are different ?? For a long time ……
Procedure 1 :
%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,0,0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,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,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,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,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;
];
B = [0,0,0,0,0,0,0.35,0.35,0.35,0.35,0.35,0.35,0,1,0,0.5,0,0,0,0,0,0,0,0]’;
Aeq = [1,1,1,1,1.005,1.005,1,-1,0.005,0.005,0.005,0.005,0.008,0.008,0.008,0.008;
1,0,0,0,0,0,0,0,-1,0,0,0,1,0,0,0;0,1,0,0,0,0,0,0,0,-1,0,0,0,1,0,0;
0,0,1,0,0,0,0,0,0,0,-1,0,0,0,1,0;0,0,0,1,0,0,0,0,0,0,0,-1,0,0,0,1];
Beq = [1,0.15,0.1,0.2,0.25]’;
x0 = [0.15,0.1,0.2,0.25,0,0,0.3,0,0,0,0,0,0,0,0,0]’;
[x,fval] = fmincon(@myfun,x0,A,B,Aeq,Beq)
%myfun.m
function f = myfun(x)
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′)
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)]’;
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/132331.html Link to the original text :https://javaforall.cn
边栏推荐
- Detailed explanation of machine learning out of fold prediction | using out of fold prediction oof to evaluate the generalization performance of models and build integrated models
- 二叉树习题总结
- MySQL tuning
- [graduation season · advanced technology Er] 10.76 million graduates, the most difficult employment season in history? I can't roll it up again. I lie down again and again. Where is the road?
- Prometheus 2.28.0 new features
- Force buckle: merging two ordered linked lists
- Getting started with mybaits (including example tutorial and source code)
- Server monitoring netdata panel configuring mail service
- 打造一个 API 快速开发平台,牛逼!
- Return value‘s Lifetime
猜你喜欢

昨天面试居然聊了半个多小时的异常处理

The imshow function of Matplotlib displays grayscale images. Vmin and vmax2 parameters should be set

pdb符号库文件详解

C language character function

力扣:合并两个有序链表

Imile uses Zadig's multi cloud environment to deploy thousands of times a week to continuously deliver global business across clouds and regions

Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!

Autonomous and controllable city! Release of the first domestic artiq architecture quantum computing measurement and control system

Deecamp2022 officially opened! Likaifu and zhangyaqin personally teach master courses 𞓜 innovation

Ordinary users use vscode to log in to SSH and edit the root file
随机推荐
记一次 .NET 某物管后台服务 卡死分析
韩国AI团队抄袭震动学界!1个导师带51个学生,还是抄袭惯犯
手把手教你在windows上安装mysql8.0最新版本数据库,保姆级教学
云原生(三十一) | Kubernetes篇之Kubernetes平台基本预装资源
##Mondo Rescue制作镜像文件(有利于镜像损坏恢复)
C language character function
PG Basics - logical structure management (1)
如何让 Dapper 支持 DateOnly 类型
C language memory function
B+ tree | MySQL index usage principle
Create an API rapid development platform, awesome!
Learn from the official motor and BLDC control strategies, and make money as soon as you learn
在线文本过滤小于指定长度工具
Discard Tkinter! Simple configuration to quickly generate cool GUI!
Hash hash game system development explanation technology -- hash game system development solution analysis
Deecamp2022 officially opened! Likaifu and zhangyaqin personally teach master courses 𞓜 innovation
Five years after graduation, I asked all the leaders around me and summarized their learning methods
mysql调优
weserver发布地图服务
Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here