0

以下示例说明了我的一般问题:

f=@(x,y) cos(x.*y);
Yvalues = linspace(0,1,50);
W = @(x) f(x,Yvalues);

如果我只想一次评估 W ,那效果很好。例如:

norm(W(pi/3)-f(pi/3,Yvalues))
ans =

      0

但是我如何在任意数量的点上评估 W 呢?

提前致谢。

4

1 回答 1

1

如果你改变

f=@(x,y) cos(x.*y);

f=@(x,y) cos(x'*y);

你可以执行 W([1 2 3])

例如,

>> f = @(x,y) cos(x'*y);
>> yv = linspace(0,1,5);
>> W = @(x) f(x,yv);
>> W(1)
ans =
    1.0000    0.9689    0.8776    0.7317    0.5403
>> W(2)
ans =
    1.0000    0.8776    0.5403    0.0707   -0.4161
>> W(3)
ans =
    1.0000    0.7317    0.0707   -0.6282   -0.9900
>> W([1 2 3])
ans =
    1.0000    0.9689    0.8776    0.7317    0.5403
    1.0000    0.8776    0.5403    0.0707   -0.4161
    1.0000    0.7317    0.0707   -0.6282   -0.9900
于 2011-09-09T22:15:03.367 回答