Does anybody know what the exact meaning of the following command?

1 次查看(过去 30 天)
Does anybody know what the exact meaning of the following command?
D = @(x,y)f(x,y).*(g(x ,y)>0);
If it possible, answer by an example.

采纳的回答

Matt J
Matt J 2023-12-6
编辑:Matt J 2023-12-6
It defines an anonymous function of x,y. Everything after @(x,y) is the expression that will be evaluated. E.g.,
D=@(x,y) x+y;
D(1,0)
ans = 1
D(1,2)
ans = 3
D(10,13)
ans = 23
  5 个评论
Walter Roberson
Walter Roberson 2023-12-6
Combining:
D = @(x,y)f(x,y).*(g(x ,y)>0);
evaluates to:
  • f(x,y) in locations where g(x,y) is > 0
  • NaN in locations where f(x,y) is -inf or +inf and g(x,y) <= 0
  • 0 in locations where f(x,y) is finite and g(x,y) <= 0
Most people forget about the inf -> nan problem: most people would summarize D as being 0 where g(x,y)<=0 and f(x,y) where g(x,y)>0 -- but that is wrong for the case of infinite f(x,y)
Matt J
Matt J 2023-12-6
编辑:Matt J 2023-12-6
can we say that D defines f only within the domain of g>0 (limits f to the domain of g>0)?
No, D is defined for all (x,y), in the sense that any (x,y) pair you give it as input will return a result. The g>0 part is simply to ensure that D=0 whenever g<=0 (assuming f(x,y) is finite for all x,y). Here is a 1D example that may make this clearer:
t=linspace(-1,1,25);
D=@(x) 2*(x>0);
plot(t,D(t),'--x'); axis padded %plot of a step fucntion
As you can see, D(t) returns plottable values for both positive and negative t. It is simply that D(t)=0 for negative t.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

标签

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by