37.利用linprog解 有约束条件多元变量函数最小值(matlab程序)
1.简述
linprog函数主要用来求线型规划中的最小值问题(最大值的镜像问题,求最大值只需要加个“-”)
2. 算法结构及使用方法
针对约束条件为Ax=b或Ax≤b的问题
2.1 linprog函数
x=linprog(f,A,b)
x=linprog(f,A,b,Aeq,beq)
x=linprog(f,A,b,Aeq,beq,lb,ub)
x=linprog(f,A,b,Aeq,beq,lb,ub,x0)
2.2 参数简介
f:目标函数
A:不等式约束条件矩阵
b:对应不等式右侧的矩阵
Aeq:等式约束条件矩阵
beq:不等式右侧的矩阵
Aeq:等式约束条件矩阵
beq:对应等式右侧的矩阵
lb:x的下界
ub:x的上界
x0:设置初始点x0,这个选择项只是对medium-scale算法有效。默认的large-scale算法和简单的算法忽略任何初始点。(一般用不到)
2.3 常用linprog函数及用法举例
linprog函数常用形式为:
x=linprog(f,A,b,Aep,beq,lb,ub);
例子: 学习目标:有约束条件多元变量函数最小值
适合 计划生产盈利最大 的模式求解,
最大值解法可转化为求解最小值算法,非常容易
求最大值转化为求最小值 f=70*x1+120*x2 的最大值,当然x1,x2是有约束的。
转化为求 f=-(70*x1+120*x2) 的最小值。
约束条件:9*x1+4*x2<=3600;4*x1+5*x2<=2000;3*x1+10*x2<=3000;-x1,-x2<
2.代码
主函数:
clc
clear
f=[-70 -120];
A=[9 4;4 5;3 10];
B=[3600;2000;3000];
Aeq=[]; Beq=[];
lb=[0 0];ub=[inf inf];
x0=[1 1];
options=optimset('display','iter','Tolx',1e-8);
[x,f,exitflag]=linprog(f,A,B,Aeq,Beq,lb,ub,x0,options)
%[xmincon,fval,exitflag,output] = fmincon(@(x)-(70*x(1)+120*x(2)),x0,A,B,Aeq,Beq,lb,ub,[],options)
子函数:
function [x,fval,exitflag,output,lambda]=linprog(f,A,B,Aeq,Beq,lb,ub,x0,options)
%LINPROG Linear programming.
% X = LINPROG(f,A,b) attempts to solve the linear programming problem:
%
% min f'*x subject to: A*x <= b
% x
%
% X = LINPROG(f,A,b,Aeq,beq) solves the problem above while additionally
% satisfying the equality constraints Aeq*x = beq. (Set A=[] and B=[] if
% no inequalities exist.)
%
% X = LINPROG(f,A,b,Aeq,beq,LB,UB) defines a set of lower and upper
% bounds on the design variables, X, so that the solution is in
% the range LB <= X <= UB. Use empty matrices for LB and UB
% if no bounds exist. Set LB(i) = -Inf if X(i) is unbounded below;
% set UB(i) = Inf if X(i) is unbounded above.
%
% X = LINPROG(f,A,b,Aeq,beq,LB,UB,X0) sets the starting point to X0. This
% option is only available with the active-set algorithm. The default
% interior point algorithm will ignore any non-empty starting point.
%
% X = LINPROG(PROBLEM) finds the minimum for PROBLEM. PROBLEM is a
% structure with the vector 'f' in PROBLEM.f, the linear inequality
% constraints in PROBLEM.Aineq and PROBLEM.bineq, the linear equality
% constraints in PROBLEM.Aeq and PROBLEM.beq, the lower bounds in
% PROBLEM.lb, the upper bounds in PROBLEM.ub, the start point
% in PROBLEM.x0, the options structure in PROBLEM.options, and solver
% name 'linprog' in PROBLEM.solver. Use this syntax to solve at the
% command line a problem exported from OPTIMTOOL.
%
% [X,FVAL] = LINPROG(f,A,b) returns the value of the objective function
% at X: FVAL = f'*X.
%
% [X,FVAL,EXITFLAG] = LINPROG(f,A,b) returns an EXITFLAG that describes
% the exit condition. Possible values of EXITFLAG and the corresponding
% exit conditions are
%
% 3 LINPROG converged to a solution X with poor constraint feasibility.
% 1 LINPROG converged to a solution X.
% 0 Maximum number of iterations reached.
% -2 No feasible point found.
% -3 Problem is unbounded.
% -4 NaN value encountered during execution of algorithm.
% -5 Both primal and dual problems are infeasible.
% -7 Magnitude of search direction became too small; no further
% progress can be made. The problem is ill-posed or badly
% conditioned.
% -9 LINPROG lost feasibility probably due to ill-conditioned matrix.
%
% [X,FVAL,EXITFLAG,OUTPUT] = LINPROG(f,A,b) returns a structure OUTPUT
% with the number of iterations taken in OUTPUT.iterations, maximum of
% constraint violations in OUTPUT.constrviolation, the type of
% algorithm used in OUTPUT.algorithm, the number of conjugate gradient
% iterations in OUTPUT.cgiterations (= 0, included for backward
% compatibility), and the exit message in OUTPUT.message.
%
% [X,FVAL,EXITFLAG,OUTPUT,LAMBDA] = LINPROG(f,A,b) returns the set of
% Lagrangian multipliers LAMBDA, at the solution: LAMBDA.ineqlin for the
% linear inequalities A, LAMBDA.eqlin for the linear equalities Aeq,
% LAMBDA.lower for LB, and LAMBDA.upper for UB.
%
% NOTE: the interior-point (the default) algorithm of LINPROG uses a
% primal-dual method. Both the primal problem and the dual problem
% must be feasible for convergence. Infeasibility messages of
% either the primal or dual, or both, are given as appropriate. The
% primal problem in standard form is
% min f'*x such that A*x = b, x >= 0.
% The dual problem is
% max b'*y such that A'*y + s = f, s >= 0.
%
% See also QUADPROG.
% Copyright 1990-2018 The MathWorks, Inc.
% If just 'defaults' passed in, return the default options in X
% Default MaxIter, TolCon and TolFun is set to [] because its value depends
% on the algorithm.
defaultopt = struct( ...
'Algorithm','dual-simplex', ...
'Diagnostics','off', ...
'Display','final', ...
'LargeScale','on', ...
'MaxIter',[], ...
'MaxTime', Inf, ...
'Preprocess','basic', ...
'TolCon',[],...
'TolFun',[]);
if nargin==1 && nargout <= 1 && strcmpi(f,'defaults')
x = defaultopt;
return
end
% Handle missing arguments
if nargin < 9
options = [];
% Check if x0 was omitted and options were passed instead
if nargin == 8
if isa(x0, 'struct') || isa(x0, 'optim.options.SolverOptions')
options = x0;
x0 = [];
end
else
x0 = [];
if nargin < 7
ub = [];
if nargin < 6
lb = [];
if nargin < 5
Beq = [];
if nargin < 4
Aeq = [];
end
end
end
end
end
end
% Detect problem structure input
problemInput = false;
if nargin == 1
if isa(f,'struct')
problemInput = true;
[f,A,B,Aeq,Beq,lb,ub,x0,options] = separateOptimStruct(f);
else % Single input and non-structure.
error(message('optim:linprog:InputArg'));
end
end
% No options passed. Set options directly to defaultopt after
allDefaultOpts = isempty(options);
% Prepare the options for the solver
options = prepareOptionsForSolver(options, 'linprog');
if nargin < 3 && ~problemInput
error(message('optim:linprog:NotEnoughInputs'))
end
% Define algorithm strings
thisFcn = 'linprog';
algIP = 'interior-point-legacy';
algDSX = 'dual-simplex';
algIP15b = 'interior-point';
% Check for non-double inputs
msg = isoptimargdbl(upper(thisFcn), {'f','A','b','Aeq','beq','LB','UB', 'X0'}, ...
f, A, B, Aeq, Beq, lb, ub, x0);
if ~isempty(msg)
error('optim:linprog:NonDoubleInput',msg);
end
% After processing options for optionFeedback, etc., set options to default
% if no options were passed.
if allDefaultOpts
% Options are all default
options = defaultopt;
end
if nargout > 3
computeConstrViolation = true;
computeFirstOrderOpt = true;
% Lagrange multipliers are needed to compute first-order optimality
computeLambda = true;
else
computeConstrViolation = false;
computeFirstOrderOpt = false;
computeLambda = false;
end
% Algorithm check:
% If Algorithm is empty, it is set to its default value.
algIsEmpty = ~isfield(options,'Algorithm') || isempty(options.Algorithm);
if ~algIsEmpty
Algorithm = optimget(options,'Algorithm',defaultopt,'fast',allDefaultOpts);
OUTPUT.algorithm = Algorithm;
% Make sure the algorithm choice is valid
if ~any(strcmp({algIP; algDSX; algIP15b},Algorithm))
error(message('optim:linprog:InvalidAlgorithm'));
end
else
Algorithm = algDSX;
OUTPUT.algorithm = Algorithm;
end
% Option LargeScale = 'off' is ignored
largescaleOn = strcmpi(optimget(options,'LargeScale',defaultopt,'fast',allDefaultOpts),'on');
if ~largescaleOn
[linkTag, endLinkTag] = linkToAlgDefaultChangeCsh('linprog_warn_largescale');
warning(message('optim:linprog:AlgOptsConflict', Algorithm, linkTag, endLinkTag));
end
% Options setup
diagnostics = strcmpi(optimget(options,'Diagnostics',defaultopt,'fast',allDefaultOpts),'on');
switch optimget(options,'Display',defaultopt,'fast',allDefaultOpts)
case {'final','final-detailed'}
verbosity = 1;
case {'off','none'}
verbosity = 0;
case {'iter','iter-detailed'}
verbosity = 2;
case {'testing'}
verbosity = 3;
otherwise
verbosity = 1;
end
% Set the constraints up: defaults and check size
[nineqcstr,nvarsineq] = size(A);
[neqcstr,nvarseq] = size(Aeq);
nvars = max([length(f),nvarsineq,nvarseq]); % In case A is empty
if nvars == 0
% The problem is empty possibly due to some error in input.
error(message('optim:linprog:EmptyProblem'));
end
if isempty(f), f=zeros(nvars,1); end
if isempty(A), A=zeros(0,nvars); end
if isempty(B), B=zeros(0,1); end
if isempty(Aeq), Aeq=zeros(0,nvars); end
if isempty(Beq), Beq=zeros(0,1); end
% Set to column vectors
f = f(:);
B = B(:);
Beq = Beq(:);
if ~isequal(length(B),nineqcstr)
error(message('optim:linprog:SizeMismatchRowsOfA'));
elseif ~isequal(length(Beq),neqcstr)
error(message('optim:linprog:SizeMismatchRowsOfAeq'));
elseif ~isequal(length(f),nvarsineq) && ~isempty(A)
error(message('optim:linprog:SizeMismatchColsOfA'));
elseif ~isequal(length(f),nvarseq) && ~isempty(Aeq)
error(message('optim:linprog:SizeMismatchColsOfAeq'));
end
[x0,lb,ub,msg] = checkbounds(x0,lb,ub,nvars);
if ~isempty(msg)
exitflag = -2;
x = x0; fval = []; lambda = [];
output.iterations = 0;
output.constrviolation = [];
output.firstorderopt = [];
output.algorithm = ''; % not known at this stage
output.cgiterations = [];
output.message = msg;
if verbosity > 0
disp(msg)
end
return
end
if diagnostics
% Do diagnostics on information so far
gradflag = []; hessflag = []; constflag = false; gradconstflag = false;
non_eq=0;non_ineq=0; lin_eq=size(Aeq,1); lin_ineq=size(A,1); XOUT=ones(nvars,1);
funfcn{1} = []; confcn{1}=[];
diagnose('linprog',OUTPUT,gradflag,hessflag,constflag,gradconstflag,...
XOUT,non_eq,non_ineq,lin_eq,lin_ineq,lb,ub,funfcn,confcn);
end
% Throw warning that x0 is ignored (true for all algorithms)
if ~isempty(x0) && verbosity > 0
fprintf(getString(message('optim:linprog:IgnoreX0',Algorithm)));
end
if strcmpi(Algorithm,algIP)
% Set the default values of TolFun and MaxIter for this algorithm
defaultopt.TolFun = 1e-8;
defaultopt.MaxIter = 85;
[x,fval,lambda,exitflag,output] = lipsol(f,A,B,Aeq,Beq,lb,ub,options,defaultopt,computeLambda);
elseif strcmpi(Algorithm,algDSX) || strcmpi(Algorithm,algIP15b)
% Create linprog options object
algoptions = optimoptions('linprog', 'Algorithm', Algorithm);
% Set some algorithm specific options
if isfield(options, 'InternalOptions')
algoptions = setInternalOptions(algoptions, options.InternalOptions);
end
thisMaxIter = optimget(options,'MaxIter',defaultopt,'fast',allDefaultOpts);
if strcmpi(Algorithm,algIP15b)
if ischar(thisMaxIter)
error(message('optim:linprog:InvalidMaxIter'));
end
end
if strcmpi(Algorithm,algDSX)
algoptions.Preprocess = optimget(options,'Preprocess',defaultopt,'fast',allDefaultOpts);
algoptions.MaxTime = optimget(options,'MaxTime',defaultopt,'fast',allDefaultOpts);
if ischar(thisMaxIter) && ...
~strcmpi(thisMaxIter,'10*(numberofequalities+numberofinequalities+numberofvariables)')
error(message('optim:linprog:InvalidMaxIter'));
end
end
% Set options common to dual-simplex and interior-point-r2015b
algoptions.Diagnostics = optimget(options,'Diagnostics',defaultopt,'fast',allDefaultOpts);
algoptions.Display = optimget(options,'Display',defaultopt,'fast',allDefaultOpts);
thisTolCon = optimget(options,'TolCon',defaultopt,'fast',allDefaultOpts);
if ~isempty(thisTolCon)
algoptions.TolCon = thisTolCon;
end
thisTolFun = optimget(options,'TolFun',defaultopt,'fast',allDefaultOpts);
if ~isempty(thisTolFun)
algoptions.TolFun = thisTolFun;
end
if ~isempty(thisMaxIter) && ~ischar(thisMaxIter)
% At this point, thisMaxIter is either
% * a double that we can set in the options object or
% * the default string, which we do not have to set as algoptions
% is constructed with MaxIter at its default value
algoptions.MaxIter = thisMaxIter;
end
% Create a problem structure. Individually creating each field is quicker
% than one call to struct
problem.f = f;
problem.Aineq = A;
problem.bineq = B;
problem.Aeq = Aeq;
problem.beq = Beq;
problem.lb = lb;
problem.ub = ub;
problem.options = algoptions;
problem.solver = 'linprog';
% Create the algorithm from the options.
algorithm = createAlgorithm(problem.options);
% Check that we can run the problem.
try
problem = checkRun(algorithm, problem, 'linprog');
catch ME
throw(ME);
end
% Run the algorithm
[x, fval, exitflag, output, lambda] = run(algorithm, problem);
% If exitflag is {NaN, <aString>}, this means an internal error has been
% thrown. The internal exit code is held in exitflag{2}.
if iscell(exitflag) && isnan(exitflag{1})
handleInternalError(exitflag{2}, 'linprog');
end
end
output.algorithm = Algorithm;
% Compute constraint violation when x is not empty (interior-point/simplex presolve
% can return empty x).
if computeConstrViolation && ~isempty(x)
output.constrviolation = max([0; norm(Aeq*x-Beq, inf); (lb-x); (x-ub); (A*x-B)]);
else
output.constrviolation = [];
end
% Compute first order optimality if needed. This information does not come
% from either qpsub, lipsol, or simplex.
if exitflag ~= -9 && computeFirstOrderOpt && ~isempty(lambda)
output.firstorderopt = computeKKTErrorForQPLP([],f,A,B,Aeq,Beq,lb,ub,lambda,x);
else
output.firstorderopt = [];
end
3.运行结果

相关文章:
37.利用linprog解 有约束条件多元变量函数最小值(matlab程序)
1.简述 linprog函数主要用来求线型规划中的最小值问题(最大值的镜像问题,求最大值只需要加个“-”) 2. 算法结构及使用方法 针对约束条件为Axb或Ax≤b的问题 2.1 linprog函数 xlinprog(f,A,b) xlinprog(f,A,b,Aeq,beq) xlinprog(f,A,b,Aeq,…...
分页Demo
目录 一、分页对象封装 分页数据对象 分页查询实体类 实体类用到的utils ServiceException StringUtils SqlUtil BaseMapperPlus,> BeanCopyUtils 二、示例 controller service dao 一、分页对象封装 分页数据对象 import cn.hutool.http.HttpStatus; import com.…...
ChatGPT超详细介绍与功能与免费网页版(超全面!)
ChatGPT ChatGPT前言ChatGPT介绍ChatGPT的优点关于ChatGPT的一些问题1.chatgpt是什么意思?2.chatgpt国内能用吗? 国内可用的ChatGPT网页版:1.ChatGPT prompts2.这个网站收集了5000多个ChatGPT 应用,可以在线运行3.ChatGPT Box4.飞书chatgpt5.AI-Produc…...
3.PyCharm安装
PyCharm是由JetBrains推出的Python开发IDE,是最受欢迎的Python IDE之一。PyCharm为Python开发者提供了许多高级功能如代码自动完成、调试等。它使用智能引擎来分析代码,能够自动识别代码中的错误并提供快速修复方案。PyCharm适用于各种规模的项目,包括小型Python脚本和大型P…...
【C语言进阶篇】关于指针的八个经典笔试题(图文详解)
🎬 鸽芷咕:个人主页 🔥 个人专栏:《C语言初阶篇》 《C语言进阶篇》 ⛺️生活的理想,就是为了理想的生活! 文章目录 📋 前言💬 指针笔试题💭 笔试题 1:✅ 代码解析⁉️ 检验结果&…...
用Rust实现23种设计模式之 策略模式
关注我,学习Rust不迷路!! 优点 灵活性:策略模式允许你在运行时动态地选择不同的算法或行为,而无需修改已有的代码。可扩展性:通过添加新的策略类,你可以轻松地扩展策略模式的功能。可维护性&a…...
面试题:说说JS的this指向问题?
1、this永远指向一个对象; 2、this的指向完全取决于函数调用的位置; 可以借鉴这篇文章,说的很详细(点击) 总结: 1、 以方法的形式调用时, this 是调用方法的对象; 2、绑定事件函…...
ansible——roles 角色
一、概述 1.roles角色简介 roles用于层次性、结构化地组织playbook。roles能够根据层次型结构自动装载变量文件、tasks以及handlers等。要使用roles只需要在playbook中使用include指令引入即可。 简单来讲,roles就是通过分别将变量、文件、任务、模板及处理器放置…...
GitHub上删除项目后,IDEA分享项目到GitHub提示Remote is already on GitHub
文章目录 一、错误信息二、解决方法1.删除GitHub上的项目2.找到项目里的.git隐藏文件3.找到config文件4.打开config文件,删除[remote "git-test"]及下面两行内容5.继续使用IDEA分享项目到GitHub即可 一、错误信息 二、解决方法 1.删除GitHub上的项目 2.…...
【机器学习 | 决策树】利用数据的潜力:用决策树解锁洞察力
🤵♂️ 个人主页: AI_magician 📡主页地址: 作者简介:CSDN内容合伙人,全栈领域优质创作者。 👨💻景愿:旨在于能和更多的热爱计算机的伙伴一起成长!!&…...
postgis mvt矢量切片 django drf mapboxgl
postgis mvt矢量切片 django drf mapboxgl 目录 0.前提 1.sql代码 2.django drf后端服务代码 3.具体的应用(整体代码) 4.参考 0.前提 [1] 静态的矢量切片可以采用 tippecanoe 生成,nginx代理,这种数据是不更新的;…...
C语言编程工具软件推荐!
1、VS(Visual Studio) [VS是目前最受欢迎的适用于Windows平台应用程序的综合开发环境,由于大多数同学使用的都是Windows操作系统,因此VS非常适合大家。在日常课堂和考试中,我们使用的VS2010支持多种不同的编程语言,VS2010最初支持…...
单体架构和微服务架构的区别
文章目录 一、单体架构的定义1. 单体架构的优点:2. 单体架构的缺点: 二、微服务架构的定义1. 微服务架构的优点:2. 微服务架构的缺点: 三、单体架构VS微服务架构1. 区别:1.1 架构规模:1.2 依赖关系…...
python--local对象、flask上下文源码分析
一、local对象 背景: 多线成并发操作一个变量,会导致数据错乱,可以使用互斥锁加锁处理数据不安全的情况 (临界区) 解决: 使用local对象处理,多个线程操作的变量是local对象,就不会…...
类文件一些内容
1、类加载 将类的字节码加载到JVM中,并转换为可以被JVM运行的数据结构的过程 类文件结构...
28 Java练习——实现两个集合的交集和并集
求并集的思路:假设传入的是一个ArrayList对象,求并集的时候直接调用其中一个List集合的addAll方法将另一个集合合并过来,而List的特性是有序,重复的。因此,使用Set接口的无序不可重复的特性,把Collection对…...
ES6学习-Promise
Promise 简单说就是一个容器,里面保存着某个未来才会结束的事件(通常是一个异步操作)的结果。 语法上: Promise 是一个对象,从它可以获取异步操作的消息。 特点 对象的状态不受外界影响。Promise 对象戴白哦一个异步操…...
《Web安全基础》03. SQL 注入
web 1:简要 SQL 注入2:MySQL 注入2.1:信息获取2.2:跨库攻击2.3:文件读写2.4:常见防护 3:注入方法3.1:类型方法明确3.2:盲注3.3:编码3.4:二次注入3…...
算法与数据结构(二十一)二叉树(纲领篇)
备注:本文旨在通过 labuladong 的二叉树(纲领篇)理解框架思维,用于个人笔记及交流学习,版权归原作者 labuladong 所有; 我刷了这么多年题,浓缩出二叉树算法的一个总纲放在这里,也许…...
visio,word添加缺少字体,仿宋_GB2312、楷体_GB2312、方正小标宋简体等字体下载
一. 内容简介 visio,word添加缺少字体,仿宋_GB2312、楷体_GB2312、方正小标宋简体等字体下载 二. 软件环境 2.1 visio 三.主要流程 3.1 下载字体 http://www.downza.cn/ 微软官方给的链接好多字体没有,其他好多字体网站,就是给你看个样式ÿ…...
设计模式和设计原则回顾
设计模式和设计原则回顾 23种设计模式是设计原则的完美体现,设计原则设计原则是设计模式的理论基石, 设计模式 在经典的设计模式分类中(如《设计模式:可复用面向对象软件的基础》一书中),总共有23种设计模式,分为三大类: 一、创建型模式(5种) 1. 单例模式(Sing…...
uni-app学习笔记二十二---使用vite.config.js全局导入常用依赖
在前面的练习中,每个页面需要使用ref,onShow等生命周期钩子函数时都需要像下面这样导入 import {onMounted, ref} from "vue" 如果不想每个页面都导入,需要使用node.js命令npm安装unplugin-auto-import npm install unplugin-au…...
Robots.txt 文件
什么是robots.txt? robots.txt 是一个位于网站根目录下的文本文件(如:https://example.com/robots.txt),它用于指导网络爬虫(如搜索引擎的蜘蛛程序)如何抓取该网站的内容。这个文件遵循 Robots…...
【Java_EE】Spring MVC
目录 Spring Web MVC 编辑注解 RestController RequestMapping RequestParam RequestParam RequestBody PathVariable RequestPart 参数传递 注意事项 编辑参数重命名 RequestParam 编辑编辑传递集合 RequestParam 传递JSON数据 编辑RequestBody …...
2025季度云服务器排行榜
在全球云服务器市场,各厂商的排名和地位并非一成不变,而是由其独特的优势、战略布局和市场适应性共同决定的。以下是根据2025年市场趋势,对主要云服务器厂商在排行榜中占据重要位置的原因和优势进行深度分析: 一、全球“三巨头”…...
基于Java Swing的电子通讯录设计与实现:附系统托盘功能代码详解
JAVASQL电子通讯录带系统托盘 一、系统概述 本电子通讯录系统采用Java Swing开发桌面应用,结合SQLite数据库实现联系人管理功能,并集成系统托盘功能提升用户体验。系统支持联系人的增删改查、分组管理、搜索过滤等功能,同时可以最小化到系统…...
Mysql中select查询语句的执行过程
目录 1、介绍 1.1、组件介绍 1.2、Sql执行顺序 2、执行流程 2.1. 连接与认证 2.2. 查询缓存 2.3. 语法解析(Parser) 2.4、执行sql 1. 预处理(Preprocessor) 2. 查询优化器(Optimizer) 3. 执行器…...
现有的 Redis 分布式锁库(如 Redisson)提供了哪些便利?
现有的 Redis 分布式锁库(如 Redisson)相比于开发者自己基于 Redis 命令(如 SETNX, EXPIRE, DEL)手动实现分布式锁,提供了巨大的便利性和健壮性。主要体现在以下几个方面: 原子性保证 (Atomicity)ÿ…...
Rust 开发环境搭建
环境搭建 1、开发工具RustRover 或者vs code 2、Cygwin64 安装 https://cygwin.com/install.html 在工具终端执行: rustup toolchain install stable-x86_64-pc-windows-gnu rustup default stable-x86_64-pc-windows-gnu 2、Hello World fn main() { println…...
永磁同步电机无速度算法--基于卡尔曼滤波器的滑模观测器
一、原理介绍 传统滑模观测器采用如下结构: 传统SMO中LPF会带来相位延迟和幅值衰减,并且需要额外的相位补偿。 采用扩展卡尔曼滤波器代替常用低通滤波器(LPF),可以去除高次谐波,并且不用相位补偿就可以获得一个误差较小的转子位…...
