简体   繁体   English

MATLAB:fzero用矩阵作为输入函数?

[英]MATLAB: fzero with a matrix as input to function?

I am trying to find the value x for a function f(x,y) that produces the function value 0 for a given y. 我试图找到函数f(x,y)的值x,它为给定的y产生函数值0。 In Matlab I write a small function handle, eg 在Matlab中我写了一个小函数句柄,例如

minme = @(y,x) y-x.^2;

and use the fzero function to find that value of x, call it x*. 并使用fzero函数查找x的值,将其称为x *。

So eg 所以,例如

fzero(@(x) minme(5,x),1)

works great. 效果很好。 However, now I want to find x* for a large vector of values of y, called Y. Putting 但是,现在我想为y的值的大向量找到x *,称为Y. Putting

minme(Y,x)

for some value of x works. 对于某些x值的作品。

Now I was trying something like 现在我正在尝试类似的东西

fzero(@(x) minme((3:1:5),x),1)

and fzero(@(x) minme(Y,x),1) 和fzero(@(x)minme(Y,x),1)

but that produces an error: ??? 但那会产生错误: ??? Operands to the || 操作数到|| and && operators must be convertible to logical scalar values. 和&&运算符必须可转换为逻辑标量值。 Error in ==> fzero at 333 elseif ~isfinite(fx) || 错误==> fzero at 333 elseif~isfinite(fx)|| ~isreal(fx) 〜伊斯雷尔(FX)

Does anybody know whether there is a way to do this? 有人知道是否有办法做到这一点?

Thanks, Immo 谢谢,Immo

看一下这个

arrayfun(@(i) fzero(@(x) minme(y(i),x),1),1:numel(y))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM