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

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Matt J
Matt J il 6 Dic 2023
Modificato: Matt J il 6 Dic 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 Commenti
Walter Roberson
Walter Roberson il 6 Dic 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 il 6 Dic 2023
Modificato: Matt J il 6 Dic 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Operating on Diagonal Matrices in Help Center e File Exchange

Tag

Prodotti


Release

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by