matlab subs 函数计算太慢

2024-01-08 23:20
文章标签 matlab 函数 计算 subs 太慢

本文主要是介绍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?

这篇关于matlab subs 函数计算太慢的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/585205

相关文章

hdu1171(母函数或多重背包)

题意:把物品分成两份,使得价值最接近 可以用背包,或者是母函数来解,母函数(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v)(1 + x^v+x^2v+.....+x^num*v) 其中指数为价值,每一项的数目为(该物品数+1)个 代码如下: #include<iostream>#include<algorithm>

poj 1113 凸包+简单几何计算

题意: 给N个平面上的点,现在要在离点外L米处建城墙,使得城墙把所有点都包含进去且城墙的长度最短。 解析: 韬哥出的某次训练赛上A出的第一道计算几何,算是大水题吧。 用convexhull算法把凸包求出来,然后加加减减就A了。 计算见下图: 好久没玩画图了啊好开心。 代码: #include <iostream>#include <cstdio>#inclu

uva 1342 欧拉定理(计算几何模板)

题意: 给几个点,把这几个点用直线连起来,求这些直线把平面分成了几个。 解析: 欧拉定理: 顶点数 + 面数 - 边数= 2。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#inc

uva 11178 计算集合模板题

题意: 求三角形行三个角三等分点射线交出的内三角形坐标。 代码: #include <iostream>#include <cstdio>#include <cstdlib>#include <algorithm>#include <cstring>#include <cmath>#include <stack>#include <vector>#include <

XTU 1237 计算几何

题面: Magic Triangle Problem Description: Huangriq is a respectful acmer in ACM team of XTU because he brought the best place in regional contest in history of XTU. Huangriq works in a big compa

C++操作符重载实例(独立函数)

C++操作符重载实例,我们把坐标值CVector的加法进行重载,计算c3=c1+c2时,也就是计算x3=x1+x2,y3=y1+y2,今天我们以独立函数的方式重载操作符+(加号),以下是C++代码: c1802.cpp源代码: D:\YcjWork\CppTour>vim c1802.cpp #include <iostream>using namespace std;/*** 以独立函数

函数式编程思想

我们经常会用到各种各样的编程思想,例如面向过程、面向对象。不过笔者在该博客简单介绍一下函数式编程思想. 如果对函数式编程思想进行概括,就是f(x) = na(x) , y=uf(x)…至于其他的编程思想,可能是y=a(x)+b(x)+c(x)…,也有可能是y=f(x)=f(x)/a + f(x)/b+f(x)/c… 面向过程的指令式编程 面向过程,简单理解就是y=a(x)+b(x)+c(x)

音视频入门基础:WAV专题(10)——FFmpeg源码中计算WAV音频文件每个packet的pts、dts的实现

一、引言 从文章《音视频入门基础:WAV专题(6)——通过FFprobe显示WAV音频文件每个数据包的信息》中我们可以知道,通过FFprobe命令可以打印WAV音频文件每个packet(也称为数据包或多媒体包)的信息,这些信息包含该packet的pts、dts: 打印出来的“pts”实际是AVPacket结构体中的成员变量pts,是以AVStream->time_base为单位的显

matlab读取NC文件(含group)

matlab读取NC文件(含group): NC文件数据结构: 代码: % 打开 NetCDF 文件filename = 'your_file.nc'; % 替换为你的文件名% 使用 netcdf.open 函数打开文件ncid = netcdf.open(filename, 'NC_NOWRITE');% 查看文件中的组% 假设我们想读取名为 "group1" 的组groupName

利用matlab bar函数绘制较为复杂的柱状图,并在图中进行适当标注

示例代码和结果如下:小疑问:如何自动选择合适的坐标位置对柱状图的数值大小进行标注?😂 clear; close all;x = 1:3;aa=[28.6321521955954 26.2453660695847 21.69102348512086.93747104431360 6.25442246899816 3.342835958564245.51365061796319 4.87