Clear Filters
Clear Filters

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

1 view (last 30 days)
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.

Accepted Answer

Matt J
Matt J on 6 Dec 2023
Edited: Matt J on 6 Dec 2023
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 Comments
Walter Roberson
Walter Roberson on 6 Dec 2023
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 on 6 Dec 2023
Edited: Matt J on 6 Dec 2023
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Tags

Products


Release

R2022b

Community Treasure Hunt

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

Start Hunting!