开发者

Evaluating multivariate functions with some arguments fixed

开发者 https://www.devze.com 2023-02-24 04:34 出处:网络
I have an anonymous multivariate function. Is it possible to f开发者_如何学Goind the value of the function by fixing one of the values?

I have an anonymous multivariate function. Is it possible to f开发者_如何学Goind the value of the function by fixing one of the values?

Here is what I would like to happen:

>> f = @(a, b) a + b;
>> f(1, b) 

ans =

    1 + b

I understand that the input I gave above is syntactically invalid, since variables must contain values. Is there a way I can accomplish this through another Matlab tool?

Thanks.


There are two ways you can accomplish this. Either, you get the symbolic toolbox, and declare b as a symbolic variable before evaluating f, or you create a new anonymous function like this:

g = @(b)f(1,b);
0

精彩评论

暂无评论...
验证码 换一张
取 消