Any math wizards out there (VB.NET)???

  • Thread starter Thread starter Brad Brening
  • Start date Start date
B

Brad Brening

Hello;

I am working in VB.NET and am trying to come up with an equation. I think
my math skills have degraded due to lack of use!

Here is my problem.

I have, say Z amount of credits to assign a user. Lets say Z = 500 credits.

I want to assign those credits over a span of, say, 10 days.

I would like the number of daily credits assigned to represent a sine
function, where the first day Joe would get a large number of credits, fewer
the second day, even fewer the third until on the 10th day the credit amount
is zero. I could represent this as X = Y(2), however that is too linear for
what I am looking to accomplish.

What I have tried to do is create 1/4 of a circle. The circumference of
this segment is Z, or 500 in this case. This is as far as I get. Knowing
X - say day 2, how can I determine my credit amount to assign?

Hopefully this makes sense, I have been beating my head off my desk for some
time over this and I may have shaken something loose!

Brad
 
Hey Brad,

Here's one idea. It takes a quadratic function that uses the square of the
number of days to reduce the amount of the credit. So day 1, the effect is
only reducing by 1, but by day 4, it's reducing by 16.

int intTotalWeight = 615; // sum of 100 - days squared over the 10 day
range
int[] aintDailyCredits = new int[9];
for (int intCntr = 0; intCntr < 10; intCntr++)
{
aintDailyCredits[intCntr] = (100 - intCntr^2) / intTotalWeight
}

It leaves you with an array of multipliers indicating16.1% percent to be
given out on day 1, 15.6% on day 2, 14.8% on day 3...

HTH,

John
 
Thanks John! That helped a bunch! I was taking the wrong approach - your
solution is great.

Brad
John Spiegel said:
Hey Brad,

Here's one idea. It takes a quadratic function that uses the square of the
number of days to reduce the amount of the credit. So day 1, the effect is
only reducing by 1, but by day 4, it's reducing by 16.

int intTotalWeight = 615; // sum of 100 - days squared over the 10 day
range
int[] aintDailyCredits = new int[9];
for (int intCntr = 0; intCntr < 10; intCntr++)
{
aintDailyCredits[intCntr] = (100 - intCntr^2) / intTotalWeight
}

It leaves you with an array of multipliers indicating16.1% percent to be
given out on day 1, 15.6% on day 2, 14.8% on day 3...

HTH,

John

Brad Brening said:
Hello;

I am working in VB.NET and am trying to come up with an equation. I think
my math skills have degraded due to lack of use!

Here is my problem.

I have, say Z amount of credits to assign a user. Lets say Z = 500 credits.

I want to assign those credits over a span of, say, 10 days.

I would like the number of daily credits assigned to represent a sine
function, where the first day Joe would get a large number of credits, fewer
the second day, even fewer the third until on the 10th day the credit amount
is zero. I could represent this as X = Y(2), however that is too linear for
what I am looking to accomplish.

What I have tried to do is create 1/4 of a circle. The circumference of
this segment is Z, or 500 in this case. This is as far as I get. Knowing
X - say day 2, how can I determine my credit amount to assign?

Hopefully this makes sense, I have been beating my head off my desk for some
time over this and I may have shaken something loose!

Brad
 
Hi Brad,

An easy way to do this would be to use the exponential equation

y = p / 2^ x --> (y equals p on 2 to the x
power)

where

p = principal amount
x = the day you want the amount for
y = the amount to be paid

this can be achieved using the following code snippet

//C#

public double calculateDailyCredit(int day, float principal)
{
double returnCredit ;
double denom ;

denom = Math.Pow(2, day) ;
returnCredit = (principal / denom) ;

return returnCredit ;
}

//VISUAL BASIC
Public Function CalculateDailyCredit(ByVal Day as Integer, BYVal Principal
as Double)

Dim ReturnCredit as Double
Dim Denominator as Double

Denominator = Math.Pow(2,day)
ReturnCredit = (Principal / Denominator)

Return ReturnCredit
End Function

Note that this is not quite complete - as for the second final day to make
the balance = 0 you need to pay out any remaining as this function will never
actually touch the X axis on a graph.

Hope this helps,
Steve.
 
Best thing for you to do is use the function of a circle. Using the x axis
as your number of days, and y axis as the credit, the amount of credit (y
axis) would reduce progressively for every increase int the value of the
day(x axis).
Just in case you didn't know, the equation of a circle is (x - a)^2 + (y -
b)^2 = r^2, where the co-ordinates (a, b) represent the center of the circle,
and r represents the radius of the circle. The radius of the circle should
correspond to the total number of days for which the credit is supposed to
last plus 1 day(in your case, 11). That way, on the day after the last day,
the credit is zero. Good luck with your program and please email me a copy
of your source code when you're done, that is of course, if it's not a
commercial product. I'd like to see what you were trying to
code.([email protected]) Good luck.
 
Back
Top