首页 > 解决方案 > 使用匿名函数 Matlab 的操作

问题描述

我需要做的一件事就是计算这个

delta_x=@(xn) (f(xn)/df(xn));

有了这个,我假装在 f 和 df 中评估我之前分配的变量 xn,它们是匿名函数并将其值相除,但在命令窗口中出现:

Error in delta_x=@(xn) (f(xn)/df(xn))

我也写过:

delta_x=f/df;

其中 f 和 df 都作为参数 xn

但是 Matlab 说:

Undefined function 'mdivide' for input arguments of type 'function_handle'. 

我需要参加这个部门,我该怎么做?

标签: matlab

解决方案


我尝试使用以下代码重现相同的错误,但没有收到任何错误

xn = [3 2 3];
%inilize function handler
d1 = @(xn) (fun1(xn)/fun2(xn));
d2 = @(xn) (fun1(xn)./fun2(xn));

%call the function
d1(xn) % = 2.1111
d2(xn) % = 2     3     2

function xout = fun1(x)
xout = x+1;
end

function yout = fun2(y)
yout = y-1;
end

我们可以知道你的matlab版本吗?


推荐阅读