0
$\begingroup$

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 ?

3 Answers 3

4

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$.

  • 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) = 02012-08-24
  • 0
    @Mohammed: What is wrong with if n=1, f(n,k)=0, else what William proposed?2012-08-24
  • 0
    if n=1 and k=50 for example , it do not return 02012-08-24
  • 0
    @Mohammed: my if statement will solve that. Are $n$ and $k$ naturals or reals? +1 for William2012-08-24
1

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.

0

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.

  • 0
    your function works well , but It did not return a value between [0,1]2012-08-25
  • 0
    @Mohammed None of these answers do, if $n,k \in \mathbb{R}$.For the other answer, take n=.00001.2012-08-25
  • 0
    You should specify that constraint in your question.2012-08-25