matlab - 使用匿名函数 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'.
我需要参加这个部门,我该怎么做?
解决方案
我尝试使用以下代码重现相同的错误,但没有收到任何错误
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版本吗?
推荐阅读
- shell - 从 Bash curl web api 请求定义的 csv 输出
- java - 使用 ArrayList 中包含的图像设置 ImageIcon
- node.js - 如何在 deno 中删除运行时导入缓存?
- java - 如何验证数组的大小?
- android - 每小时在 SQLite db 中插入一行以获取特定 ID(不是唯一的)
- c++ - OpenFileMapping 有多贵?(内存映射文件)
- javascript - Redux Reducer 或组件的 ShouldComponentUpdate 中的深度比较?
- mysql - DBContext Hell,使用 LINQ 调用 mySQL 数据库的正确方法
- arrays - Swift:我的哈希表适用于幻数,但不适用于动态数字
- javascript - 我知道如何将 if 语句写成公式,但不是在脚本中