matlab fmincon 精度,fmincon与quadprog误差

matlab fmincon 精度,fmincon与quadprog误差该楼层疑似违规已被系统折叠隐藏此楼查看此楼有没有人能帮我看看这两个程序的运行结果为什么会不一样啊??困扰了好久……程序一:%text1.mclearall;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.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,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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)]’;

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/132331.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)


相关推荐

  • SD卡、TF卡、MMC卡以及eMMC芯片的介绍「建议收藏」

    SD卡、TF卡、MMC卡以及eMMC芯片的介绍「建议收藏」一、SD卡   1、简介       SD卡为SecureDigitalMemoryCard,即安全数码卡,是一种基于半导体快闪记忆器的新一代记忆设备。它在MMC的基础上发展而来,增加了两个主要特色:SD卡强调数据的安全,可以设定所储存的使用权限,防止数据被他人复制;另外一个特色就是传输速度比2.11版的MMC卡快。   2、外观及引脚定义   3、特性

  • pytest parametrize fixture_参数化数据

    pytest parametrize fixture_参数化数据前言当某个接口中的一个字段,里面规定的范围为1-5,你5个数字都要单独写一条测试用例,就太麻烦了,这个时候可以使用pytest.mark.parametrize装饰器可以实现测试用例参数化。官方示

  • IOC控制反转与DI依赖注入

    IOC控制反转与DI依赖注入新建UserDao接口新建UserDaoImpl实现类IOC控制反转与DI依赖注入~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~开发工具与关键技术:IntellijIDEASpring作者:周欢撰写时间:2021/1/19~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~IOC(控制反转)作用:实现将组件间的关系从程序内部提…

  • php类自动载入

    php类自动载入

  • JAVA获取uuid_java uri类

    JAVA获取uuid_java uri类UUID获取以及格式化没有什么描述的直接看代码

  • mmap 内存映射详解

    mmap 内存映射详解mmap基础概念mmap是一种内存映射的方法,这一功能可以用在文件的处理上,即将一个文件或者其它对象映射到进程的地址空间,实现文件磁盘地址和进程虚拟地址空间中一段虚拟地址的一一对映关系。在编程时可以使某个磁盘文件的内容看起来像是内存中的一个数组。如果文件由记录组成,而这些记录又能够用结构体来描述的话,可以通过访问结构数组来更新文件的内容。实现这样的映射关系后,进程就可以采用指针的方式读写操…

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号