MATLAB:使用矩阵作为函数的输入的fzero? [英] MATLAB: fzero with a matrix as input to function?

查看:352
本文介绍了MATLAB:使用矩阵作为函数的输入的fzero?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到函数f(x,y)的值x,该函数对于给定的y产生函数值0.在Matlab中,我编写了一个小的函数句柄,例如

I am trying to find the value x for a function f(x,y) that produces the function value 0 for a given y. In Matlab I write a small function handle, e.g.

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

并使用fzero函数找到x的值,将其称为x *.

and use the fzero function to find that value of x, call it x*.

例如.

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

效果很好.但是,现在我想找到一个名为y的较大向量y的x *.放置

works great. However, now I want to find x* for a large vector of values of y, called Y. Putting

minme(Y,x)

对于x的某些值有效.

for some value of x works.

现在我正在尝试类似的东西

Now I was trying something like

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

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

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

但是会产生一个错误: ??? ||的操作数和&&运算符必须可转换为逻辑标量值. ==> fzero的333错误 elseif〜isfinite(fx)|| 〜isreal(fx)

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) || ~isreal(fx)

有人知道是否有办法吗?

Does anybody know whether there is a way to do this?

谢谢, Immo

推荐答案

检查一下

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

这篇关于MATLAB:使用矩阵作为函数的输入的fzero?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆