You are welcome, please call me Jeffrey.
I can give you a few first impressions. 

   Usespace,itfreesyouandinformsme:   ==>   Use space, it frees you and 
informs me:
   R[1]=mOil[2]/(mOil[2]-mOil[1])+b   ==>   R[1] = mOil[2]/(mOil[2] - 
mOil[1]) + b

Time wells in loops, any savings inside a 600x loop is 600 of the same 
thing each outside the loop.  You can lift any unchanging indirect 
references out of loops:

     firstR = mOil[2]/(mOil[2] - mOil[1]) + b
     R[1] = firstR
     (loop)
         R[i+1] = firstR - i*b
     end

"Yes" is the way to answer "Should this be a function instead of the more 
difficult to follow way that it is inlined here?"
My guide to naming functions: use names with words or obvious shortenings 
and choose names that will make sense this time next year and others can 
follow.

Julia really does go fast.  It is important to follow the guidelines: 
performance-tips 
<http://julia.readthedocs.org/en/latest/manual/performance-tips/> and 
(after that) fast numerics <http://julialang.org/blog/2013/09/fast-numeric/>
.

And this, from the collective wisdom: "get it right then get it fast"

Feedback

On Friday, August 21, 2015 at 5:01:49 PM UTC-4, Tj Midkiff wrote:
>
> Thank you Jeff.
>
> On Friday, August 21, 2015 at 3:51:41 PM UTC-5, Jeffrey Sarnoff wrote:
>>
>> you created R to hold 600 things, things indexable as R[1]..R[600]
>>
>> mnths=600
>> R=zeros(Float64,mnths)
>>
>> later you bring Julia's attention to R[600+1], just one step 'out of 
>> bounds'
>> when i is 600, i+1 is 601
>>
>> In Julia, the top part of the range is included
>> That loop should be
>>
>> for i in 3:(600-1)
>>   R[i+1] = ..
>> end
>>
>>
>> On Friday, August 21, 2015 at 4:37:48 PM UTC-4, Tj Midkiff wrote:
>>>
>>> I am trying to write a small script to help my company out.  I came 
>>> across Julia on a web search naturally when looking for more speed.  I am 
>>> just getting my feet wet with programming so please be patient with me.
>>>
>>> This is one piece of the code that I know is very inefficient, so any 
>>> help is greatly appreciated.  FYI, the final version will include pulling 
>>> the initial variables from a SQL database that could include 100k records.  
>>> So basically this code could be ran 100k times in the final version at any 
>>> time (along with many more calculations).  Please comment anywhere I could 
>>> add more efficiency, because speed is absolutely critical.
>>>
>>> I have a spreadsheet I can provide that shows the methodology a little 
>>> clearer if it would help.
>>>
>>> My main question though is why am I getting the BoundsError()...
>>>
>>> Thanks for all of the help.
>>>
>>>
>>> qi=3454.0
>>> di=0.6
>>> b=0.9
>>> mnths=600
>>>
>>> AI=(1/b)*((1-di)^-b-1)
>>> ai=AI/12
>>> q(t)=qi/(1+b*ai*t)^(1/b)
>>> Q=[q(t-1) for t=1:3]
>>> a=((Q[2]/Q[3])^b-1)/b
>>> mOil=zeros(Float64,mnths)
>>>
>>> #Is it worth creating a function here?
>>> mOil[1]=(Q[1]^b/((1-b)*ai))*(Q[1]^(1-b)-Q[2]^(1-b))
>>> mOil[2]=(Q[2]^b/((1-b)*a))*(Q[2]^(1-b)-Q[3]^(1-b))
>>> R=zeros(Float64,mnths)
>>> R[1]=mOil[2]/(mOil[2]-mOil[1])+b
>>> for i=1:2
>>>   R[i+1]=R[1]-i*b
>>> end
>>>
>>> for i=3:600 #Getting a BoundsError() here
>>>    #mOil[i]=mOil[i-1]*(R[i]/(R[i]-1))
>>>    R[i+1]=R[1]-i*b
>>> end
>>>
>>>
>>>

Reply via email to