Filter löschen
Filter löschen

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

1 Ansicht (letzte 30 Tage)
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.

Akzeptierte Antwort

Matt J
Matt J am 6 Dez. 2023
Bearbeitet: Matt J am 6 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 6 Dez. 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 am 6 Dez. 2023
Bearbeitet: Matt J am 6 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Operating on Diagonal Matrices finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by