# Linear algebra matrix coding to solve specific formula

I have a formula which cannot be expressed in terms of y.

fv = (p (1 + r) (-1 + (1 + r)^m) ((1 + r)^(m y) - (1 + x)^y))/
(r (-1 + (1 + r)^m - x)) + c (1 + r)^(m y)


I'd like to solve it numerically with some kind of matrix operation.

For example

with

r = 0.05/12
m = 12
p = 1000
x = 0.03
c = 2000
fv = 92988.93


Can this be done with linear algebra, or is an iterative approach necessary?

Wolfram Alpha is not giving any clues for a matrix solution. Maybe some gradient descent program is required.

• Can you please define what you mean by "solve it numerically"? It sounds like you are looking for an algorithm to do something. What are the inputs to the algorithm, and what is the desired output?
– D.W.
Jan 27 at 23:35
• Welcome to Computer Science! Note that you can use LaTeX here to typeset mathematics in a more readable way. See here for a short introduction.
– D.W.
Jan 27 at 23:36
• @D.W. I have solved before some simultaneous equations with a single-step formula obtained from matrix calculations. I just wonder if there is a computational technique for solving these formulae that can't be expressed in terms of a single variable. Jan 28 at 0:00
• That doesn't answer my questions.
– D.W.
Jan 28 at 0:08
• @D.W. The inputs are r, m, p, c, x, fv and the expected output is y = 6. (Reals only) Iteration looks unavoidable. Jan 28 at 0:17

Linear algebra and matrices are not relevant here. Roughly speaking, they are useful when you have a system of linear equations. Here, you have a single equation, not a system of equations; and it is nonlinear.

If I understand correctly, given $$p,m,\dots$$, you are trying to find a value of $$y$$ that satisfies the equation. This equation can be written in the form

$$f(y) = 0$$

where $$f$$ is a function of $$y$$ (it also depends on $$p,m,\dots$$ but those are considered known constants). Here $$f(y) = (p(1+r)\cdots) - fv$$.

You can find an approximate solution to such an equation using an iterative algorithm, such as Newton's method. See https://en.wikipedia.org/wiki/Root-finding_algorithms.

• I'm pretty sure Newton's is the way to go, thanks. Jan 28 at 0:21

From what I see, your equation has the form

$$A(1+a)^y+B(1+b)^y+C=0$$ where $$a,b$$ are small. Such a nonlinear equation cannot be solved analytically.

To find an approximate solution, you can write

$$0=A(1+a)^y+B(1+b)^y+C\approx A(1+ay)+B(1+by)+C$$ and solve for $$y$$. An even better approximation comes from

$$0=A(1+a)^y+B(1+b)^y+C\\\approx A\left(1+ay+a^2\frac{y(y-1)}2\right)+B\left(1+by+b^2\frac{y(y-1)}2\right)+C$$

which is quadratic in $$y$$ (by the generalized binomial formula).

Then you can refine with Newton's method. Few iterations will be needed.

$$y\leftarrow y-\frac{A(1+a)^y+B(1+b)^y+C}{A\log(1+a)(1+a)^y+B\log(1+b)(1+b)^y}.$$

• Very useful, thanks. Feb 2 at 13:51

Newton-Raphson solution for n

Need to find a root for this formula with one unknown, n

(p ((1 + r)^n - (1 + x)^n))/(r - x) + c (1 + r)^n - fv = 0


Using the algorithm here: https://en.wikipedia.org/wiki/Newton%27s_method#Code

This method requires the derivative of the formula.