ID:151671
 
I have an equation that calculates the amount of mana a spell will cost based on how strong you are choosing to make it.

The problem is that in the actual implementation the player will choose how much mana they want to use, not the direct strength of the spell, and the strength of the spell needs to be calculated from there.

The equation for calculating mana cost from spell power is this (i is spell power):
TotalCost=Cost*i*(1+(i/20)**2)

I have tried and had a few friends (far from math geniuses) try to rebalance the equation into the shape I'd like it, but to no avail.

The only step I could even manage is shifting one of the i's to the left side and the TC to the right side. The result of which being this:
i=(C*(1+(i/20)**2)) * (1/TC)

Any changes I try to make after that result in inequalities.
I tried using www.mathway.com to solve it for me, but the results it gives don't properly reproduce the results of the first equation. Also I'm not a 'subscriber' there so I can't see the steps they took to even get any ideas.

Can anyone either verify that it is impossible to move both i's to one side by themselves (a format I could use in BYOND calculations. Could be i, i*X, i**X, whatever.) or give me insight on the next step to take in doing so?
Cubic inverses are ugly. You can find the cubic formula here.

I suggest working out a less-ugly formula. The exponential function would be a good choice.
In response to Garthor
Garthor wrote:
Cubic inverses are ugly. You can find the cubic formula here.

I suggest working out a less-ugly formula. The exponential function would be a good choice.

That is what Stephen suggested. :)

A good idea.

I end up using a lot of repeating squares / roots to create an appropriately curved formula for what I want.
Changing i to s since in math i tends to mean something else, you can solve for s like so:

T = c * s * (1+(s/20)^2)
T/c = s * (1+(s/20)^2)
T/c = s + s(s/20)^2
T/c = s + s^3/400
s^3 + 400s - T/c = 0

From there it's just a matter of solving the cubic equation. I'm not really that well-versed on solving cubics myself, but I can tell you the format of this equation is going to leave you with only one positive result and two complex ones that you can discard.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
T/c = s + s^3/400
s^3 + 400s - T/c = 0

Are you sure about those? I got this:
s3 + 400s - 400T/c = 0

Here's my logic, starting with:
T/c = s + s3/400
400T/c = 400s + s3 --- (multiply both sides by 400)
400s + s3 - 400T/c = 0 --- (subtract 400T/c from both sides)
In response to Kuraudo
Kuraudo wrote:
Lummox JR wrote:
T/c = s + s^3/400
s^3 + 400s - T/c = 0

Are you sure about those? I got this:
s3 + 400s - 400T/c = 0

Ah, yes, I made an error in there. Good find.

Lummox JR
In response to Lummox JR
Lummox JR wrote:
Kuraudo wrote:
Lummox JR wrote:
T/c = s + s^3/400
s^3 + 400s - T/c = 0

Are you sure about those? I got this:
s3 + 400s - 400T/c = 0

Ah, yes, I made an error in there. Good find.

Lummox JR

Thank you both for the equations.

Due to my lack of interwebs at home now I ended up already creating a new equation that mirrors the results from this equation pretty well.

I appreciate the help though. A good insight into a math problem that I was struggling with for quite awhile. :)