d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Math Question
Add Reply New Topic New Poll
Member
Posts: 35,043
Joined: Mar 31 2010
Gold: 105,913.26
Nov 30 2020 04:46pm


My math classes are mostly a blur at this point, so I have a (hopefully) simple question.
Answers in mathematical formulas / javascript / python / any programming language are fine.

I want to be able to provide the value of X, Ymax, and a coefficient for the steepness of the curve.
When X = 100 (percent), Y must be = Ymax
When X = 0, Y must be = 0

or in code

Code
function getValue(x, ymax, steep) {
return Math.pow(ymax, x / 100);
}


Of course this one doesn't adjust for steepness though.
The red line on the graph is another idea, of maybe having no steepness control but rather the curve being bound to three points, so that I can have more control over when the curve gets really sharp.
If you can answer the latter, even better.

This post was edited by laztheripper on Nov 30 2020 04:47pm
Member
Posts: 12,703
Joined: May 17 2013
Gold: 12,935.00
Dec 1 2020 02:09pm
can't you just create a function of the format

Code
y = (e^x/c) + N * x + K

where c is some arbitrary fraction, N and K are arbitrary integers

then you can adjust c to be larger for a less steep curve, or a small c for a really steep curve.
K changes your starting values, N allows for finer scaling

if it's not what you're looking for, good luck ¯\_(ツ)_/¯

This post was edited by Klexmoo on Dec 1 2020 02:10pm
Member
Posts: 35,043
Joined: Mar 31 2010
Gold: 105,913.26
Dec 1 2020 03:36pm
Quote (Klexmoo @ Dec 1 2020 03:09pm)
can't you just create a function of the format

Code
y = (e^x/c) + N * x + K

where c is some arbitrary fraction, N and K are arbitrary integers

then you can adjust c to be larger for a less steep curve, or a small c for a really steep curve.
K changes your starting values, N allows for finer scaling

if it's not what you're looking for, good luck ¯\_(ツ)_/¯


Yes that works and I've thought of that, but the problem is that the max Y value at X=100 must be exact and I'd have to calculate those magic numbers that were added to change the curve to preserve Ymax

This post was edited by laztheripper on Dec 1 2020 03:36pm
Member
Posts: 30,945
Joined: Apr 13 2008
Gold: 11,996.69
Dec 1 2020 03:47pm
I dont know if that would work, but can you use taylor polynomials ?

edit: post in homework help hotline, maybe feanur will answer you there :P

This post was edited by moutonguerrier on Dec 1 2020 03:54pm
Member
Posts: 94
Joined: Jun 6 2008
Gold: 0.00
Dec 7 2020 10:30pm
Let me rephrase your problem to make sure I understand it. So you want to find an exponential function f(x) which has two points at (0,0) and (100,Ymax) with a variable steepness coefficient, right?

If so, I would start from a general function like,
y = k * (e^(c*x) - 1); where k is "fit" constant and c is the "steepness" coefficient.

The k value depends on the value of c, so you would need to calculate it inside the function but it's easy to figure out what it is.
y_max = k * (e^(c*100) - 1); plugging in the values we know
k = (y_max) / (e^(c*100) -1 ); dividing both sides by the exponential part

Or you can just simplify the whole thing and substitute the k to the first general function.
y = ((y_max) / (e^(c*100) - 1)) * (e^(c*x) - 1)

so in pseudo-code
function y(x,y_max,c)
y = (y_max / (e^(c*100) - 1)) * (e^(c*x) - 1)
return y

This post was edited by liljohn_jy on Dec 7 2020 10:41pm
Member
Posts: 35,043
Joined: Mar 31 2010
Gold: 105,913.26
Dec 9 2020 11:39am
Quote (liljohn_jy @ Dec 7 2020 11:30pm)
Let me rephrase your problem to make sure I understand it. So you want to find an exponential function f(x) which has two points at (0,0) and (100,Ymax) with a variable steepness coefficient, right?

If so, I would start from a general function like,
y = k * (e^(c*x) - 1); where k is "fit" constant and c is the "steepness" coefficient.

The k value depends on the value of c, so you would need to calculate it inside the function but it's easy to figure out what it is.
y_max = k * (e^(c*100) - 1); plugging in the values we know
k = (y_max) / (e^(c*100) -1 ); dividing both sides by the exponential part

Or you can just simplify the whole thing and substitute the k to the first general function.
y = ((y_max) / (e^(c*100) - 1)) * (e^(c*x) - 1)

so in pseudo-code
function y(x,y_max,c)
y = (y_max / (e^(c*100) - 1)) * (e^(c*x) - 1)
return y


This is exactly what I'm looking for. :)
Member
Posts: 94
Joined: Jun 6 2008
Gold: 0.00
Dec 9 2020 05:04pm
nice, thank you for the fg lol.
Member
Posts: 35,043
Joined: Mar 31 2010
Gold: 105,913.26
Dec 9 2020 05:10pm
Quote (liljohn_jy @ Dec 9 2020 06:04pm)
nice, thank you for the fg lol.


;) thank you
Member
Posts: 94
Joined: Jun 6 2008
Gold: 0.00
Dec 10 2020 02:24am
Let me know if you need anything else
Member
Posts: 4,544
Joined: Sep 22 2013
Gold: 0.00
Warn: 80%
Dec 16 2020 12:02am
Maths are the language of DEVIL! eVILZ are afoot!
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll