Borrar filtros
Borrar filtros

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

1 visualización (últimos 30 días)
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.

Respuesta aceptada

Matt J
Matt J el 6 de Dic. de 2023
Editada: Matt J el 6 de Dic. de 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 comentarios
Walter Roberson
Walter Roberson el 6 de Dic. de 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 el 6 de Dic. de 2023
Editada: Matt J el 6 de Dic. de 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.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by