<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Iterative sum in Mathematical Optimization, Discrete-Event Simulation, and OR</title>
    <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166370#M850</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks I've corrected my formula but it's still giving me the same numbers that are way&amp;nbsp; too high.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dATA LSV.right;&lt;/P&gt;&lt;P&gt;set lsv.left;&lt;/P&gt;&lt;P&gt;right=0;&lt;/P&gt;&lt;P&gt;do i=0 to n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; right= comb(n,i)* (i/n) * ((1-Pt)**(n-i)) * abs ((i/n) -Pt) +right;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 04 Jul 2014 15:31:44 GMT</pubDate>
    <dc:creator>crikriek</dc:creator>
    <dc:date>2014-07-04T15:31:44Z</dc:date>
    <item>
      <title>Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166368#M848</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;I'm facing an&amp;nbsp; issue when doing an itrative sum using factorials. This is the first time I use both an iterative sum and the FACT function so I guess there are a&amp;nbsp; lot of things wrong in my code.&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Want I want is the formula I hereby attached. The output should always be between 0 and 1 since Pt is always around 0,5. Nevertheless ith my formula I obtain totlly different numbers that can be super high.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;STRONG style="color: navy; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;dATA&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; LSV.right;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; lsv.left;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;right=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;do&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; i=&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;0&lt;/STRONG&gt; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;to&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt; n;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calc1=fact(n) / fact(i) / fact(n-i);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; calc2= calc1 * i/n ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;calc3=calc2* (&lt;/SPAN&gt;&lt;STRONG style="color: teal; background: white; font-size: 10.0pt; font-family: 'Courier New';"&gt;1&lt;/STRONG&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;-Pt)**(n-i) ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;calc4= calc3* abs ((i/n) -Pt);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; right=calc4 + right;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; abs=abs((i/n)-Pt);&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Prod=calc1*calc2*calc3*calc4;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;end&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: blue; background: white;"&gt;run&lt;/SPAN&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: .0001pt;"&gt;&lt;SPAN style="font-size: 10.0pt; font-family: 'Courier New'; color: black; background: white;"&gt;Could you please help me with that ? thanks&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/11774iDAC755DFA97A8038/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="formula.PNG" title="formula.PNG" /&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jul 2014 08:00:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166368#M848</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-04T08:00:53Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166369#M849</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like you are multiplying everything twice.&amp;nbsp; You can just skip the last two lines (abs and Prod) in the body of the loop.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, you can use the COMB function to compute calc1 directly, without using FACT.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jul 2014 15:04:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166369#M849</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2014-07-04T15:04:26Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166370#M850</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks I've corrected my formula but it's still giving me the same numbers that are way&amp;nbsp; too high.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;dATA LSV.right;&lt;/P&gt;&lt;P&gt;set lsv.left;&lt;/P&gt;&lt;P&gt;right=0;&lt;/P&gt;&lt;P&gt;do i=0 to n;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; right= comb(n,i)* (i/n) * ((1-Pt)**(n-i)) * abs ((i/n) -Pt) +right;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&amp;nbsp; run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jul 2014 15:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166370#M850</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-04T15:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166371#M851</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, your code now seems to match your formula.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's possible that you are running into overflow issues, in which case you'll need to be more careful about the order of operations.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What sort of values are you expecting, and what are you getting instead?&amp;nbsp; (We don't have your data.)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What is your formula supposed to calculate?&amp;nbsp; Are you maybe missing a Pt**i factor?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 04 Jul 2014 16:36:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166371#M851</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2014-07-04T16:36:32Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166372#M852</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A colleague has suggested using a log transformation to reduce the scale and help avoid overflow.&amp;nbsp; He sent this code:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data&amp;nbsp; left;&lt;BR /&gt;input n pt;&lt;BR /&gt;cards;&lt;BR /&gt;1000 0.9995&lt;BR /&gt;1000 0.95&lt;BR /&gt;1000 0.5&lt;BR /&gt;1000 0.005&lt;BR /&gt;run;&lt;BR /&gt;data right;&lt;BR /&gt;&amp;nbsp; set left;&lt;BR /&gt;&amp;nbsp; sum = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp; /****************************************************/&lt;BR /&gt;&amp;nbsp; /* when i = 0 term = 0&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;&amp;nbsp; /* the last term is always bounded by max(1,abs(pt) */&lt;BR /&gt;&amp;nbsp; /* with pt small log1px(-pt) should be used&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;&amp;nbsp; /* consider using lbeta instead of lfacts&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;BR /&gt;&amp;nbsp; /****************************************************/&lt;BR /&gt;&amp;nbsp; log1mpt = log(1-pt);&lt;BR /&gt;&amp;nbsp; do i=0 to n;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (i = 0) then&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logterm = -10000000; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&amp;nbsp; do;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; logterm = lfact(n) - lfact(i) - lfact(n-i)&amp;nbsp; + log(i/n) + (n-i) * log1mpt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sum= sum + exp(logterm) * abs(i/n-pt); &lt;BR /&gt;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp; put sum=;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 10 Jul 2014 20:26:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166372#M852</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2014-07-10T20:26:37Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166373#M853</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks a lot.&amp;nbsp; i just fund out my problem. I was a misintepretation of the formula. As you said earlier I&amp;nbsp; had forgotten a&amp;nbsp; Pt**i factor. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you very much for your precious help.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Jul 2014 07:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166373#M853</guid>
      <dc:creator>crikriek</dc:creator>
      <dc:date>2014-07-11T07:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Iterative sum</title>
      <link>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166374#M854</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Glad to help.&amp;nbsp; Please mark this question as Answered.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 11 Jul 2014 12:19:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Mathematical-Optimization/Iterative-sum/m-p/166374#M854</guid>
      <dc:creator>RobPratt</dc:creator>
      <dc:date>2014-07-11T12:19:39Z</dc:date>
    </item>
  </channel>
</rss>

