旧版本MATLAB中的符号导数抛出错误
我有一个MATLAB代码,它使用符号函数进行某些操作,旧版本MATLAB中的符号导数抛出错误,matlab,symbolic-math,backwards-compatibility,Matlab,Symbolic Math,Backwards Compatibility,我有一个MATLAB代码,它使用符号函数进行某些操作,sym/diff函数在我的服务器的2015b版本中运行时抛出了一个非常恼人的错误。我的笔记本电脑与2018a运行相同的代码没有问题。错误尤其是: Error using sym/diff (line 68) Error using class The first argument to function CLASS must be a struct. 引发错误的代码部分的MWE如下所示: Thrust_fcn = @(r) 5 * exp(
sym/diff
函数在我的服务器的2015b版本中运行时抛出了一个非常恼人的错误。我的笔记本电脑与2018a运行相同的代码没有问题。错误尤其是:
Error using sym/diff (line 68)
Error using class
The first argument to function CLASS must be a struct.
引发错误的代码部分的MWE如下所示:
Thrust_fcn = @(r) 5 * exp(-2*r)
syms r;
diff_fcn = diff(Thrust_fcn, r);
这是引发错误的内置sym/diff函数中的代码:
try
if nargin == 1
r = class(maplemex(0,'MTM:-diff',m),'sym');
elseif nargin == 2
r = class(maplemex(0,'MTM:-diff',m,n),'sym');
else
r = class(maplemex(0,'MTM:-diff',m,n,u),'sym');
end
catch
error(lasterr);
end
我已经检查了2018a上的sym/diff
函数的代码,它是完全不同的,大约300行代码
你有什么办法让它发挥作用吗?非常感谢 符号功能
当您使用@(r)
时,您正在生成一个函数\u句柄
,它不是符号工具箱的一部分:
>> Thrust_fcn = @(r) 5 * exp(-2*r);
>> whos Thrust_fcn
Name Size Bytes Class Attributes
Thrust_fcn 1x1 32 function_handle
相反,先尝试创建r
,然后使用symr
>> syms r;
>> Thrust_fcn = 5 * exp(-2*r); %%% Not using @(r)! %%%
>> whos Thrust_fcn
Name Size Bytes Class Attributes
Thrust_fcn 1x1 8 sym
既然推力fcn是一个符号,试着调用diff(推力fcn,r)
调用MuPAD函数(在MATLAB中)
如果您想继续使用函数句柄,可以在MATLAB编辑器中使用MuPAD的功能。
解释了使用MuPAD函数的几种方法,但我将提供一个工作示例:
% Notice that 'syms r' is never called.
% You may want to ensure your previous variable 'r' has been cleared first.
clear r;
Thrust_fcn = @(r) 5 * exp(-2*r);
feval(symengine,'diff',Thrust_fcn,'r')
这与您在MuPAD中定义函数的方式相同,使用输入在笔记本电脑中安装2015并为同一版本编写代码时,调用
struch\u fcn
。。。。