How to define such a simple function in Mathematica

  • Context: Mathematica 
  • Thread starter Thread starter nrqed
  • Start date Start date
  • Tags Tags
    Function Mathematica
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
4 replies · 2K views
Messages
3,762
Reaction score
297
A very simple question but I can't find an answer.

I have an expression which depends on two integers, n,d.
Now, I want this expression to be

a) 1 when d=n=0,

b) some expression (that I won't write here) when both d and n are >0

c) zero when wither d or n negative.

At first I defined the function using Kronecker deltas and the Heaviside Theta function but the problem is that the expression that is valid when d and n are greater than 0 contains a factor d/n, and even if the Heaviside Theta function is zero when d=n=0, Mathematica gets an indeterminate result because of the division by n. I want to force it to be zero.

Thank you!
 
Physics news on Phys.org
Dale said:
What about when d=0 and n>0 or d>0 and n=0.
Sorry, it is zero in that case.
So I have a function that

a) is defined to be some expression for both n and d >0

b) equal to 1 when d=n=0

c) zero in all other cases.
 
Try
Code:
f[n_Integer, d_Integer] :=
 Piecewise[{{expr, (d > 0) && (n > 0)}, {1, (d == 0) && (n == 0)}}, 0]
 
  • Like
Likes   Reactions: berkeman and nrqed
Dale said:
Try
Code:
f[n_Integer, d_Integer] :=
Piecewise[{{expr, (d > 0) && (n > 0)}, {1, (d == 0) && (n == 0)}}, 0]
Thank you!
Perfect!
 
  • Like
Likes   Reactions: berkeman and Dale