当前位置: 首页 > news >正文

MATLAB(R2023a)添加工具箱TooLbox的方法-以GPOPS为例

一、找到工具箱存放位置

首先我们需要找到工具箱的存放位置,点击这个设置路径可以看到
image-20230806213305862

image-20230806213305862

我们的matlab工具箱的存放位置

C:\Program Files\MATLAB\R2023a\toolbox\matlab

从资源管理器中打开这个位置,可以看到里面各种工具箱

二、放入工具箱

解压我们的工具箱gpops,可以看到里面有两个文件夹

image-20230806213305862

将这两个文件夹直接放到上面的工具箱存放位置,可以复制也可以剪切。

三、添加文件

这时我们可以添加我们的工具箱了

image-20230806213305862

点击添加并包含子文件,找到之前的那两个文件的位置,也就是

C:\Program Files\MATLAB\R2023a\toolbox\matlab\lib

C:\Program Files\MATLAB\R2023a\toolbox\matlab\nlp

将这两个文件添加并包含子文件。

然后就可以在matlab程序中用这两个工具箱了

四、测试GPOPS

刚刚我们添加的工具箱是GPOPS2的工具箱,现在可以测试一下这个工具箱

clc;clear;close all;
tic;
% 设置时间
t0 = 0;
tf = 2;
% 设置状态量初值
x10 = -2;
x20 = 1;
% 设置状态量边界条件
x1Min = -5;
x1Max = 5;
x2Min = -5;
x2Max = 5;
% 设置控制量边界条件
uMin  = -1.5;
uMax  = 1.5;bounds.phase.initialtime.lower  = t0; 
bounds.phase.initialtime.upper  = t0;
bounds.phase.finaltime.lower    = tf; 
bounds.phase.finaltime.upper    = tf;
bounds.phase.initialstate.lower = [x10 x20]; 
bounds.phase.initialstate.upper = [x10 x20];
bounds.phase.state.lower        = [x1Min x2Min]; 
bounds.phase.state.upper        = [x1Max x2Max];
bounds.phase.finalstate.lower   = [0 0];
bounds.phase.finalstate.upper   = [0 0];
bounds.phase.control.lower      = uMin; 
bounds.phase.control.upper      = uMax;
bounds.phase.integral.lower     = 0; 
bounds.phase.integral.upper     = 10000;guess.phase.time     = [t0; tf]; 
guess.phase.state    = [[x10; 0],[x20; 0]];
guess.phase.control  = [1; uMin];
guess.phase.integral = 100;setup.name = 'Vehicle-Stopping-OCP';
setup.functions.continuous  = @vsopcContinuous;
setup.functions.endpoint   	= @vsopcEndpoint;
setup.bounds                = bounds;
setup.guess                 = guess;
setup.nlp.solver            = 'snopt';
setup.derivatives.supplier  = 'sparseCD';
setup.derivatives.derivativelevel = 'second';
setup.mesh.method           = 'hp1';
setup.mesh.tolerance        = 1e-6;
setup.mesh.maxiteration     = 45;
setup.mesh.colpointsmax     = 4;
setup.mesh.colpointsmin     = 10;
setup.mesh.phase.fraction   = 0.1*ones(1,10);
setup.mesh.phase.colpoints  = 4*ones(1,10);
setup.method = 'RPMintegration';output = gpops2(setup);
solution = output.result.solution;
toc;%% 函数模块部分
% ----------------------------------------------------------------------- %
% ------------------------- BEGIN: vsopcContinuous.m -------------------- %
% ----------------------------------------------------------------------- %
function phaseout = vsopcContinuous(input)
t  = input.phase.time;
% x1  = input.phase.state(:,1);
x2  = input.phase.state(:,2);
u   = input.phase.control(:,1);dx1 = x2;
dx2 = u;phaseout.dynamics = [dx1, dx2];
phaseout.integrand = 0.5*u.^2;
end
% ----------------------------------------------------------------------- %
% -------------------------- END: vsopcContinuous.m --------------------- %
% ----------------------------------------------------------------------- %% ----------------------------------------------------------------------- %
% -------------------------- BEGIN: vsopcEndpoint.m --------------------- %
% ----------------------------------------------------------------------- %
function output = vsopcEndpoint(input)J  = input.phase.integral;
output.objective = J;
end
% ----------------------------------------------------------------------- %
% --------------------------- END: vsopcEndpoint.m ---------------------- %
% ----------------------------------------------------------------------- %

这里我们直接使用了别人的程序来进行测试,测试结果是正确的。

http://www.lryc.cn/news/111947.html

相关文章:

  • 助力618-Y的混沌实践之路 | 京东云技术团队
  • Python系统学习1-4-物理行、逻辑行、选择语句
  • 学习系统编程No.35【基于信号量的CP问题】
  • 词嵌入、情感分类任务
  • TypeScript使用技巧
  • MySQL — InnoDB事务
  • LeetCode 42. 接雨水(动态规划 / 单调栈)
  • 顺序表、链表刷题指南(力扣OJ)
  • Lambda表达式总结
  • 岛屿的最大面积
  • 迭代器模式(Iterator)
  • Goland搭建远程Linux开发
  • react中PureComponent的理解与使用
  • 洛谷——P5714 【深基3.例7】肥胖问题
  • Mac隐藏和显示文件
  • 软件工程中应用的几种图辨析
  • 下载离线版的VS Visual Studio 并下载指定的版本
  • Eureka 学习笔记5:InstanceRegistry
  • System Verilog——虚方法的使用
  • 线性规划和单纯形法-原理篇
  • FBX SDK开发快速上手指南
  • 探讨|使用或不使用机器学习
  • Git笔记--Ubuntu上传本地项目到github
  • 基于Go编写一个可视化Navicat本地密码解析器
  • Maven【入门笔记】
  • Android Studio中使用cmake开发JNI实战
  • 第七章 图论
  • IEEE SystemVerilog Chapter13 : Tasks and functions (subroutines)
  • day39反转字符串总结
  • 使用Socket实现TCP版的回显服务器