I am working on a little project (in a very "low Level" language with single-precision 32-bit float that nearly has no functionality apart from basic conditions and loops) and at one point I have to solve a linear system of equations (4x4 or sometimes 5x5). This is not the problem, I use the GAUSSian algorithm with pivoting. To increase the speed of calculation, it is also possible to use a straight-forward coded explicit solution of the 4x4 system (e.g. gained from Matlabs symbolic toolbox.)

The problem I have to deal with is now that sometimes in my system of equations there can occur exponential functions eb with quite high exponents, lets say b>10000 ... the thing is that these huge values vanish when the system is solved. The next thing is that b are no integer values but some decimal things ...

Is there a way for a quick kind of "factorization" of for example e13421.1234? Or what can I do to make my equation-system solvable?

Edit: example-set of equations

x_i = 0 ... >1000               = values from Measurement, i.e. time in days]
y_i = 0, 1e-6 ... 1e-4          = values from Measurement, i.e. creep-strain]
b_i = 1/1, 1/10, 1/100, 1/1000  = constants
a_i = Regression-Parameters to be estimated

(1): ( a_1*sum_{i=1}^{k}*e^{x_i*(b_1+b_1)} +
       a_2*sum_{i=1}^{k}*e^{x_i*(b_2+b_1)} +
       a_3*sum_{i=1}^{k}*e^{x_i*(b_3+b_1)} +
       a_4*sum_{i=1}^{k}*e^{x_i*(b_4+b_1)} ) = ( sum_{i=1}^{k} y_i*e^{x_i*b_1} )

(2): ( a_1*sum_{i=1}^{k}*e^{x_i*(b_1+b_2)} +
       a_2*sum_{i=1}^{k}*e^{x_i*(b_2+b_2)} +
       a_3*sum_{i=1}^{k}*e^{x_i*(b_3+b_2)} +
       a_4*sum_{i=1}^{k}*e^{x_i*(b_4+b_2)} ) = ( sum_{i=1}^{k} y_i*e^{x_i*b_2} )

(3): ( a_1*sum_{i=1}^{k}*e^{x_i*(b_1+b_3)} +
       a_2*sum_{i=1}^{k}*e^{x_i*(b_2+b_3)} +
       a_3*sum_{i=1}^{k}*e^{x_i*(b_3+b_3)} +
       a_4*sum_{i=1}^{k}*e^{x_i*(b_4+b_3)} ) = ( sum_{i=1}^{k} y_i*e^{x_i*b_3} )

(4): ( a_1*sum_{i=1}^{k}*e^{x_i*(b_1+b_4)} +
       a_2*sum_{i=1}^{k}*e^{x_i*(b_2+b_4)} +
       a_3*sum_{i=1}^{k}*e^{x_i*(b_3+b_4)} +
       a_4*sum_{i=1}^{k}*e^{x_i*(b_4+b_4)} ) = ( sum_{i=1}^{k} y_i*e^{x_i*b_4} )
  • Have you searched for algorithms for exponentiation?
    – Andrew
    Commented Aug 21, 2017 at 21:50
  • @AndrewPiliser, yes I did but was not sure if that works also for exponents which are no integers Commented Aug 22, 2017 at 7:46
  • @DocBrown The numbers from e^b come from my input data. I have a set of $n$ equations with $n$ unknowns. This system results if I do the linear regression-algorithm. But I am not sure if it is solveable if the input-values are large scaled. Commented Aug 22, 2017 at 7:48
  • looks like the factor 1/k is superfluous?
    – Doc Brown
    Commented Aug 22, 2017 at 8:56

2 Answers 2


So these are four or five linear equations (in four or five unknowns) with your $e^b$'s as coefficients, is that right?

Then I'd think you can divide all the terms of an equation by any constant you like. And each equation has four or five $e^{b_i},i=1...4or5$ coefficients. So just look for the smallest $b_i$ (in each equation separately) and subtract it out from each, i.e., $b_i-->b_i-b_{min}$ in that equation. Do that separately for each equation, and it should leave the overall solution unchanged.

Since you say "these huge values vanish when the system is solved", that implies that the $b_max-b_min$'s can never be very large. So when you subtract out the $b_min$'s, that should leave the remaining $e^{b_i-b_min}$'s tractable.

  • You're right. This are $n$ linear equations in $n$ unknowns with $e^b$ as coefficients. I'll add an example of my equation-system in the original question. Commented Aug 22, 2017 at 7:55
  • I think this answer is a pointer into the right direction. I guess it may be better, however, to look for the biggest exponent, not for the smallest.
    – Doc Brown
    Commented Aug 22, 2017 at 9:13
  • Thats true, I also thought about it before; but my problem is that the equation-system is a kind of very badly scaled so that there occur rather big coefficients besides rather small ones. Commented Aug 22, 2017 at 9:20
  • @Questionmarkengineer Okay, so those a_i's are the unknowns. Your Eq(4) looks particularly bad with b_1+b_4=1.001 and b_4+b_4=0.002 multiplying the x_i's, which could lead to exponents with max-min pretty large. You might want to try posting your question in scicomp.stackexchange.com where it may be more on-topic (and where mathjax works:) Commented Aug 22, 2017 at 9:35
  • @Questionmarkengineer But with "rather big coefficients besides rather small ones" (your remark in preceding comment, agreeing with my observation about Eq.4), how does your original post remark that "these huge values vanish when the system is solved" work??? You're essentially inverting a matrix with some very big elements and some very small ones. Offhand, I'm not seeing how your "huge values vanish". Commented Aug 22, 2017 at 9:41

This SO answer has some C code for implementing pow and exp.

If you want to implement it yourself, recall that exp(a + b) = exp(a) + exp(b) (mathematically, at least). If you have a floating point number, you can treat it as the sum of an integer part and a decimal part, x = n + d. exp(n) can be computed with repeated multiplication, and then you just have to find exp(d).

With a Taylor series around 0 (technically a Maclaurin series (: ), that can be computed as d + (d^2 / 2) + (d^3 / 6) + ... + (d^k / k!). Since those powers are all integers, they can be computed with repeated multiplication.

Take the results from the two parts above, multiply them, and you have exp(x).

I don't totally like the idea of repeatedly multiplying e, but you could implement base 2 exponentiation and compute exp(x) = 2^(x / log_2(e)). Integer powers of 2 can be computed with bitshifting, but then the Taylor series for the decimal part would be off. I'm not sure which would be more accurate overall.

Keep in mind that there are potential numerical analysis issues here, especially with negative numbers. I don't think there would be any problems, but I would recommend thorough testing of your algorithm before using it in production. Specific things to watch out for are how far you want to take the Taylor series, negative bases and exponents, and combinations of very small and very large values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.