# Formulate mathematical equation

I have a function:

$$f(n) = 1 - \left(\frac{1}{n}\right)$$

I want to add another variable $k$ to this equation such that: if $k=n$ , then $f(n,k)=1$
if $n=1$, then $f(n,k)=0$ How can we do that ?

-

Consider the function

$g(n,k) = 1 - \frac{1}{n} + \frac{1}{k}$

Then if $k = n$, you have $g(n,k) = 1$. (Note that $n$ and $k$ can not be equal to $0$.)

As Ross Millikan suggested, for your new question, you can consider the function:

$$h(n,k) = \begin{cases} g(n,k) & \quad n \neq 1 \\ 0 & \quad n = 1 \end{cases}$$

$h$ is a perfectly good function and satisfy the property that $n \neq 1$ and $k = n$, then $h(n,k) = 1$; and if $n = 1$, then for all $k$, $h(n,k) = 0$.

-
I am sorry I did not notice your answer, I've changed the question. I need also if n=1 , then f(n,k) = 0 –  M.A Aug 24 '12 at 3:45
@Mohammed: What is wrong with if n=1, f(n,k)=0, else what William proposed? –  Ross Millikan Aug 24 '12 at 4:06
if n=1 and k=50 for example , it do not return 0 –  M.A Aug 24 '12 at 4:08
@Mohammed: my if statement will solve that. Are $n$ and $k$ naturals or reals? +1 for William –  Ross Millikan Aug 24 '12 at 4:24

For the first part, a key point is that if $ab=0$, then $a=0$ or $b=0$. So this suggests that whatever you add on should be multiplied by what you already have, since the equation as you give it solves $f(1,k)=0$. Multiplying all that by something won't change the result.

Similarly, for the second part, what simple relationship gives $1$ when two numbers are equal? There's a basic operation that does exactly what you want for that part. Stick them together and you should have a suitable solution.

-

Assuming that the following statement will never be true - n=k=1 - you can also do this without an "if" statement. Try $(1-\frac{1}{n})^{n-k}$. If n=1, then the fraction $\frac{1}{n}$ will be $\frac{1}{1}=1$, and $1-1=0$. $0^{anything} = 0$. The other issue is if $n=k$. In this case, $n-k = 0$ and $anything^0 = 1$.

I think this equation is also good because at $f(1,1)$, your constraints have given both of the values $0$ and $1$, so it is undefined at $f(1,1)$. At $f(1,1)$, my equation gives you $0^0$, which is undefined.

-
your function works well , but It did not return a value between [0,1] –  M.A Aug 25 '12 at 14:24
@Mohammed None of these answers do, if $n,k \in \mathbb{R}$.For the other answer, take n=.00001. –  mathguy Aug 25 '12 at 14:31
You should specify that constraint in your question. –  mathguy Aug 25 '12 at 14:32