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

matlab subs 函数计算太慢

来源

计算机器人 transformation matrix 相关内容时,对于关节角度进行离散,循环计算很慢,随着角度划分越来越细,怎么提高速度是一个问题。

最优解决方法

fun_handle = matlabFunction(T_t2b_RPY_tmp);

T_t2b_RPY_tmp是 transformation matrix, 其中使用 符号类型 syms 关节角度,直接把它转换成函数。注意查看函数变量顺序

fun_handle =function_handle with value:@(theta_P,theta_R,theta_Y)reshape([cos(theta_Y).*sin(theta_R)+cos(theta_R).*sin...

然后直接使用循环进行计算


tic
fun_handle = matlabFunction(T_t2b_RPY_tmp);
AAA = zeros(4,4,prod(num_point));
p = 0;
for i = Rollfor j = Pitchfor k = Yawp = p + 1;AAA(:,:,p) = fun_handle(j,i,k);endend
end
toc

使用符号计算 时间差别 上千倍

tic
BBB = zeros(4,4,prod(num_point));
p = 0;
for i = Rollfor j = Pitchfor k = Yawp = p + 1;BBB(:,:,p) = double(subs(T_t2b_RPY_tmp, {theta_R theta_P theta_Y}, {i j k}));endend
end
toc

问题:两个计算结果有差别

把两者结果作差,D1 = AAA-BBB;, 可以看到结果不一样,不过都小于 10^-4.

val(:,:,1) =1.0e-15 *0    0.0000         0         00   -0.0612         0         00.0612         0    0.0000    0.61230         0         0         0val(:,:,2) =1.0e-04 *-0.2846    0.0000    0.2190    0.1895-0.2190   -0.0000   -0.2846    0.15370.0000         0    0.0000    0.00000         0         0         0val(:,:,3) =1.0e-04 *-0.1169    0.0000    0.4760   -0.2399-0.4760   -0.0000   -0.1169   -0.16910.0000         0    0.0000    0.00000         0         0         0
isequal(round(AAA,5), round(BBB,5)) 对比精度

这个是由于两者计算精度不一样,具体原理没有搞清楚,详情参考

  • Why is there a significant difference in the assignment results of functions using “subs” and “feval”
  • Problem of creating function handle from the result of symbolic differentiation
  • Getting different results from function handle & syms for a same equation. How to avoid it?
  • Why I got different result by using matlabFunction and subs to do symbolic substitution?
http://www.lryc.cn/news/281093.html

相关文章:

  • 如何确保网络传输的安全性和稳定性?
  • 鸿蒙应用开发学习:改进小鱼动画实现按键一直按下时控制小鱼移动和限制小鱼移出屏幕
  • 紫光展锐5G扬帆出海 | Blade系列勇当拉美5G先锋
  • 如何设计一个高并发系统?
  • 基于WebRTC技术的EasyRTC视频云服务系统在线视频客服解决方案
  • 黑马程序员——2022版软件测试——乞丐版——day04
  • uniapp微信小程序投票系统实战 (SpringBoot2+vue3.2+element plus ) -创建图文投票实现
  • Spring系列学习九、Spring MVC的使用
  • 开源内容管理系统Wagtail本地安装运行并结合内网穿透实现公网访问
  • 【蓝桥杯/DFS】路径之谜 (Java)
  • Go语言的内存分配器
  • Swift单元测试Quick+Nimble
  • 详解电源动态响应的测试方法及重要性 -纳米软件
  • 计算机网络系统结构-2020期末考试解析
  • 二叉树的遍历 Java
  • 数据结构之str类
  • Java电影购票小程序在线选座订票电影
  • 24-1-9 bilibilic++音视频
  • 备案(三)
  • Hotspot源码解析-第十九章-ClassLoaderData、符号表、字符串表的初始化
  • impala元数据自动刷新
  • 骑砍战团MOD开发(35)-射击精度系统
  • 树莓派非常实用的程序-3 vcdbg
  • jmeter分布式服务搭建
  • vue中el-radio无法默认选中
  • 分布式I/O应用于智慧停车场的方案介绍
  • node后端+vue前端实现接口请求时携带authorization验证
  • SourceTree管理git
  • 【数模百科】一篇文章讲清楚灰色预测模型GM(1,1)附python代码
  • openssl3.2 - 官方demo学习 - mac - hmac-sha512.c