Solve these equations...

Blitz3D Forums/Blitz3D Programming/Solve these equations...

sswift(Posted 2004) [#1]
Given the following equations, how can I solve for A and B?

Given:
R1, R2, T1, T2, E

R1 = A * E^(B * T1)
R2 = A * E^(B * T2)

I have no idea how to simplify when B's in that exponent like that. I found some stuff on how to solve two equations with two unknowns, so I know it's possible in at least some cases but it doesn't cover getting stuff out of exponents.


fredborg(Posted 2004) [#2]
I don't know the English terms for this, but this shows how to resolve an exponent on the opposite side of the equal sign:
a# = 45.0
pow# = 23.0
b# = a^pow
c# = b^(1.0/pow)
Print a
Print c
WaitKey()
End



sswift(Posted 2004) [#3]
So you're saying that if:

b = a^p

Then to solve for a instead you'd get:

a = b^(1/p)

Seems to make sense...


fredborg(Posted 2004) [#4]
Yes!

And to get T1 and B seperated this should work:

E^(B*T1) = (E^T1) ^ (B)

Which should make it possible to move B to the other side of the equal sign in your original equation :)


sswift(Posted 2004) [#5]
Well so far what I've got is

R1 = A * E^(B*T1)
R2 = A * E^(B*T2)

And the first can be rearranged to:
A = R1 / E^(B*T1)

Combining the second with the rearranged one, I get:
R2 = (R1 / (E ^(B*T1)) * E^(B*T2)

At which point I'm at a loss for how to get B on the right side of the equation alone. Your example:

B = A^P
Rearranged to:
A = B^(1/P)

Does not show me how to get P on the right side of the equation alone, which is what I need to do apparently to solve this.

So if
B = A^P
How can I rearrange it to the following form?
P = ?

In other words, given 256 = 2^P solve for P.


Koriolis(Posted 2004) [#6]
B = A^P = Exp(P*Log(A))

Thus P * Log(A) = Log(B),
Thus P = Log(B) / Log(A)


sswift(Posted 2004) [#7]
Oh my god...

I just noticed you sig. AUGH!

You're GIVING away the very thing I was working to develop to sell! :-)

I'm reffering to tree[d]!

Of course it doesn't work as intuitively as what I was trying to develop would. But it's close enough to make me question whether I should bother with my own fractal plant generator.

The reason I've been trying to solve this logarithm thing is because it models plant growth, and produces nice curves.

Basically, the idea was this. I wanted a formula which would allow one to make a cylinder, or a cone. Make it straight, bent, or in a spiral form.

So I would allow the user to specify an initial segment length, and create a set of vertices in a circle at the base, and them move a pivot in it's own space up this distance. Then I'd turn and twist it according to the specified turn and twist angle, which remain constant over the length of the branch. Then I'd create a new circle of vertcies in it's space on it's XZ plane, and move it forward again in whatever direction it's Y axis was now pointing. I'd also change the scale of the circles I was making, and the distance I moved it each time, based on the taper value, which would be like 0.98 to scale each bit down by 2%.

But where I was haivng the problem was with a last parameter I wanted to add. Subdivision. I wanted to allow the user to create additional circles of vertcies between those that were already there. But to do this I did not know how I should alter my angle and distance traveled, in such a way that the shape of the logarithmic spiral I was generating would remain the same. I basically wanted to just smooth the 3d model generated.

Anyhow I may reconsider bothering with this now. It's been nothing but a pain in the ass for the last week trying to get folks to help me with this logartihmic stuff. I've asked here, and on IRC in three different channels and on Flipcode and gotten little assistance, present company excluded of course. You've given me some good information.

Hm...

So yeah... I'm nt sure if I'm gonna pursue this any more. Besides this there's also TreeMagik. But the difference between this and TreeMagik was to be the amount of control you have over the model which you don't apparently have in TreeMagik.

So maybe I'll go back to working on that other system I was working on.


puki(Posted 2004) [#8]
Hey "sswifty" - what's 'squishysoft'? Is it a secret project?


sswift(Posted 2004) [#9]
Squishysoft?

That's this:
http://lightning.prohosting.com/~sswift/

That's the name of my "company" at the moment. I put it on some of my older projects. I've been considering just saying "Shawn Swift's whatever" though instead. It's not actually registered as a company or anything.


fredborg(Posted 2004) [#10]
tree[d] uses bezier's which it manipulates, this makes it relatively straightforward to interpolate while keeping the same shape.

It doesn't really create realistic trees with fractal growth but it produces nice enough results :)


puki(Posted 2004) [#11]
'Shawn Swift Software'


eBusiness(Posted 2004) [#12]
Edited

R1 = A * E^(B * T1) <=>
1/A = (E^B)^T1 / R1 <=>
A = R1 / E^(B * T1)

R2 = A * E^(B * T2) <=>
1/A = (E^B)^T2 / R2

(E^B)^T1 / R1 = (E^B)^T2 / R2 <=>
(E^B)^(T1-T2) = R1 / R2 <=>
E^B = (R1 / R2)^(1/(T1-T2)) <=>
B = ln((R1 / R2)^(1/(T1-T2)))/ln(E)

Note that the equation will have an endless number of solutions if T1=T2.


Floyd(Posted 2004) [#13]
The equations have many 'variables'. However, all but A,B have known values.
So we have two equations in two unknowns. This has a solution, we just need to find it.

As already mentioned, the Log function is the key.

It simplifies everything. Multiplication becomes addition, and exponentiation becomes multiplication.

Log follows these rules:

1. Log(x*y) = Log(x) + Log(y)
2. Log(x^y) = y * Log(x)

This all started with the polar equation R = A*Exp(B*theta).

Taking logarithms changes this to Log(R) = Log(A) + B*theta.

In this case A,B are considered as known and R,theta are the variables.
Filling in known values gives a simple equation, e.g. Log(R) = 5 + 3*theta.

That explains why the corresponding graph is called a Logarithmic Spiral.


Matty(Posted 2004) [#14]
It is not too hard to solve for A and B simply do the following:
(easier with pen and paper so I will use * for multiply here)
R1=A*exp(B*t1)
R2=A*Exp(B*t2)

(ln is log to the base e here)

ln(R1)= ln(A) + B*t1 , this is equation 1
ln(R2)= ln(A) + B*t2 , this is equation 2

Multiply equation 1 by t2/t1

(t2/t1)*ln(R1) = (t2/t1)*ln(A) + B*t2 , this is equation 3

subtract equation 2 from equation 3

(t2/t1)*ln(R1) - ln(R2) = (t2/t1)*ln(A) - ln(A), and the B terms cancel giving us equation 4

Solve equation 4 for A:

(t2/t1)*ln(R1) - ln(R2) = ((t2/t1) - 1)*ln(A)

ln(A) = [(t2/t1)*ln(R1) - ln(R2)]/[(t2/t1)-1]

so A = exp[(t2/t1)*ln(R1) - ln(R2)]/[(t2/t1)-1]

then solve for B by substituting A back into either equation 1 or equation 2, we shall do equation 1.

ln(R1) = ln(A) + B*t1

B = [ln(R1) - ln(A)]/t1

B = (ln(R1)/t1) - [(t2/t1)*ln(R1) - ln(R2)]/[(t2/t1)-1]/t1

which gives us our equations for A and B


sswift(Posted 2004) [#15]
Thanks... I though there was a way to solve that. And now I know how to use logarithms to cancel out exponents, which might come in handy at some point in the future.