Use Variables to Create Function

Silva

New member
Hi everyone.

I'm currently trying to create a function/expression based on several variables. I've so far figured out the rules that the variables should follow but I'm struggling to put them together into a formula. I'm hoping that someone here might tell me if this is even possible, and give me some advice or direct me somewhere specific I can read about my problem (I haven't studied any maths in some time and I don't recall an exact name for what I'm trying to do).

To give my variables names I'll be using: a, b, m, p, s, x
The relations I'd like to have are:

Code:
a ≥ x ≥ b > 0
a ≥ 1 ≥ b > 0
m ≥ s ≥ 0
m ≥ p ≥ 0
when s = p then x = 1
when p = m and s = 0 then x = a
when s = m and p = 0 then x = b
I'd like to show x as a function using these variables.

Thanks in advance for any help.

Last edited:

topsquark

Well-known member
MHB Math Helper
Hi everyone.

I'm currently trying to create a function/expression based on several variables. I've so far figured out the rules that the variables should follow but I'm struggling to put them together into a formula. I'm hoping that someone here might tell me if this is even possible, and give me some advice or direct me somewhere specific I can read about my problem (I haven't studied any maths in some time and I don't recall an exact name for what I'm trying to do).

To give my variables names I'll be using: a, b, m, p, s, x
The relations I'd like to have are:

Code:
a ≥ x ≥ b > 0
a ≥ 1 ≥ b > 0
m ≥ s ≥ 0
m ≥ p ≥ 0
when s = p then x = 1
when p = m and s = 0 then x = a
when s = m and p = 0 then x = b
I'd like to show x as a function using these variables.

Thanks in advance for any help.
It might be possible to do it from here but it might be easier if we knew what we were trying to achieve. Would this be some kind of polynomial? An exponential? A sinusoidal? Can you tell us the whole problem?

-Dan

Silva

New member
Hi Dan, thanks for your response. I'll try my best to explain what I'm doing. I'm extending a game engine to implement a system where the players character has a particular parameter, while other characters have a similar parameter. These parameter influences the effect of a skill/ability.

x will determine the multiplier that's applied to the skill/ability.
a is the maximum the multiplier can be (maximum for x)
b is the minimum the multiplier can be (minimum for x)
s is one of the character's parameter value
p is the other character's parameter value
m is the maximum the parameter value can be
As p increases relative to s, x should increase. If p > s, x > 1. If p < s, x < 1. If p = s, m = 1.

I think an exponential best suits this, rate of change for p-s (I think).

Silva

New member
I've managed to solve this by creating a new variable, x, and defining it as m+s-p, thank you, Dan, for helping me see that I could do this. I created a quadratic regression formula using the variables to calculate known values, ran them together as simultaneous equations to find an expression for the first "constant", substituted this into one of the original formulas to find an expression for the second constant. I'm not sure it consistently meets all the rules I'd defined but from the tests I've done it seems to be fine.

The end result should anyone be interested:

Klaas van Aarsen

MHB Seeker
Staff member
Hi Silva, welcome to MHB!

Let's define $P=\frac p m$ and $S=\frac s m$ to simplify the relations.
And let's call our function $x(P,S)$.
Then we have:
\begin{cases}x(1,0)=a\\ x(0,1)=b\\ x(q,q)=1&\text{for any }q
\end{cases}

The simplest relation would be a linear relation in $P$ and $S$, but we can see that it won't work, since it will put a restriction on $a$ and $b$ that is undesired.

Let's try a polynomial of degree 2:
$$x(P,S)=AP^2+BS^2+CPS +DP+ES+F$$
Then we have:
$$\begin{cases}x(1,0)=A+D+F=a\\ x(0,1)=B+E+F=b\\ x(q,q)=(A+B+C)q^2+(D+E)q+F=1 \end{cases}\implies \begin{cases}A+D+F=a\\ B+E+F=b\\ A+B+C=0\\ D+E=0\\ F=1 \end{cases}$$
If we pick $D=E=0$, we get:
$$\begin{cases}A=a-1\\ B=b-1\\ C=2-a-b\\ D=E=0\\ F=1 \end{cases}\implies x(P,S)=(a-1)P^2+(b-1)S^2+(2-a-b)PS+1$$

So we can use:
$$x(p,s)=(a-1)\left(\frac pm\right)^2+(b-1)\left(\frac sm\right)^2+(2-a-b)\frac{ps}{m^2}+1$$

EDIT: I was writing this before I saw you posted again.

topsquark

Well-known member
MHB Math Helper
I've managed to solve this by creating a new variable, x, and defining it as m+s-p, thank you, Dan, for helping me see that I could do this.
Ummmm..... You're welcome? I'm glad you got it, but I doubt I did any thing.

-Dan

Silva

New member
Hi Klaas van Aarsen, glad to be here.

Thanks for finding a solution for this. I've tested your solution and it's not quite functioning as I'd intended (nor is mine after testing that further). It works correctly when s = p, when s = 0 and p = m, when p = 0 and s = m. The issue I have with both mine and your solution is that when s = m and p is slightly more than 0 then the result doesn't always meet this condition:

a ≥ x ≥ b > 0

As x < b. Using your equation this condition is only satisfied when:

1 - b ≥ a - 1
so, a = 1.7, b = 0.3 is okay but a = 1.8, b = 0.3 is not.

Similarly for my equation this condition is only satisfied when:

(1 - b) * 3 ≥ a - 1

Can you think of any way we can solve so that the condition a ≥ x ≥ b ≥ 0 is always met, or is this not possible?

Dan, had you not asked what kind of equation I wanted I wouldn't have known what my options were for solving it. Credit where credit's due.