I have discovered formulas to build an Investment Calculator using the compound interest (TVM) concept formula. The base of the formula is as follows:

Find Future Value:
FV = P(1 + r/n)^(nt) + PMT * [(((1 + r/n)^(nt)) - 1) / (r/n)]

Find Monthly Contribution Amount (PMT):
(FV - P(1 + r/n)^(nt)) / [((1 + r/n)^(nt) - 1) / (r/n)]

Find Initial Investment Amount/Principal (P):
(FV - (PMT * [((1 + r/n)^(nt) - 1)]) / (r/n)]) / ((1 + r/n)^(nt))

I have researched many sources, but it seems like there is no formula that can directly calculate the following:

i) Does anyone have a way to solve for t if
P = 1,000
r = 5
n = 12 (compound monthly)
PMT = 100 (contribute every end of the month)
FV = 40,000

Find t by rearranging the formula t = ?

or any other method?

ii) Does anyone have a way to solve for r if
P = 1,000
t = 10 years
n = 12 (compound monthly)
PMT = 100 (contribute every end of the month)
FV = 40,000

Find r by rearranging the formula r = ?

or any other method?

I have searched for methods, but they only mention using trial and error to calculate due to the nature of the formula. Besides, I have been looking for a formula to solve it, but only found simple lump sum formulas without PMT. I need the experts to help as my brain is bursting these few days. Thanks!!!!!!â¤ï¸â¤ï¸â¤ï¸â¤ï¸