# Re: Math Problem in Mathematica

```
Daniel wrote:

> The problem I would like to formulate in Mathematica is: Let f[i,j] =
> Abs[Sqrt[1-(i/n)^2]-j/n]. i and j run from  1 to n, and n is a fixed
> integer >=1.  I want to find the  sum S of the minimum of f over j, for
> each i for given n.
>
> Example: n=7.  Min (i=1, j from 1 to 7)= .01
>                Min (i=2, """          )= .04
>                Min (i=3, ...           = .05
>                etc.
>
> and the sum S = 0.20.

Daniel:Since this is discrete it can be tackled it directly f[i_,j_,n_]
:= Abs[Sqrt[1-(i/n)^2]-j/n]

s[n_] := Sum[ Min[Table[f[i,j,n]//N,{j,1,n}]],{i,1,n}]

s[20]//Timing

{3.86667 Second,0.262656}

Or by looking at

Solve[(n^2-i^2)==j^2,j]

{{j -> -Sqrt[-i^2 + n^2]}, {j -> Sqrt[-i^2 + n^2]}}

and allowing for the case i = n

s2[n_]:=Sum[Min[N[ f[i,#,n]]&/@({
Max[#,1],Max[#+1,1]}&[Floor[Sqrt[n^2-i^2]]])],{i,1,n}]

s2[20]//Timing

{0.533333 Second,0.262656}

--
Allan Hayes
Training and Consulting
Leicester, UK
hay@haystack.demon.co.uk
http://www.haystack.demon.co.uk
voice: +44 (0)116 271 4198
fax: +44 (0)116 271 8642

```

• Prev by Date: Re: Easy question: Infinite Series, Infinite Sequences
• Next by Date: Re: tensor/matrix calculations
• Prev by thread: Re: Math Problem in Mathematica
• Next by thread: OneIdentity and x__ patterns