Double summation + other defined variable

160936089_3806056046116957_8627175637072356544_n

Hi, I am currently dealing with this math problem and I don't know how to transfer this calculation (shown in picture) into R.

I wish to express this as the function of N (and plot it in the graph for j=1:9)
The alpha_i(j) stands for the no. of the integers 1:i that its first digit is j.
And I have created a function: first_digit() to return the first digit of a positive integer.

The script below is so far I've done.
My goal is to try to get the result of the first summation (which should be in terms of i and N)
Then sum up for i=1:N to get the final result

The major problem is that I do not know how to incorporate two summations together.
Could anyone give me some idea? Thanks a lot!

repla1<-1
prob.a<-function(N){
 	for(i in 1:N){
 		v<-c(1:i)
 		alpha=0
 		for(b in 1:i){
  			repla1=first_digit(v[b])
  			alpha=alpha+1
		}
		k = i:N
		sum(alpha/(k*N))

See this post for the approach.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.