How to define such a simple function in Mathematica

  • Thread starter nrqed
  • Start date
  • #1
nrqed
Science Advisor
Homework Helper
Gold Member
3,764
293
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!
 

Answers and Replies

  • #3
nrqed
Science Advisor
Homework Helper
Gold Member
3,764
293
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.
 
  • #4
Dale
Mentor
Insights Author
2020 Award
31,406
8,108
Try
Code:
f[n_Integer, d_Integer] :=
 Piecewise[{{expr, (d > 0) && (n > 0)}, {1, (d == 0) && (n == 0)}}, 0]
 
  • Like
Likes berkeman and nrqed
  • #5
nrqed
Science Advisor
Homework Helper
Gold Member
3,764
293
Try
Code:
f[n_Integer, d_Integer] :=
Piecewise[{{expr, (d > 0) && (n > 0)}, {1, (d == 0) && (n == 0)}}, 0]
Thank you!!
Perfect!
 
  • Like
Likes berkeman and Dale

Related Threads on How to define such a simple function in Mathematica

Top