Optimize Common Parameters Across Several Equations Using Least Squares In Python
I would like to optimize common parameters among several equations, but i dont know how to fit them simultaneously. The problem is essentially like this, with four equations to so
Solution 1:
This is a system of 4 equations with 4 unknowns. It can be solved algebraically.
solving for a, b, and c and plugging into the first equation. I'm assuming the (*100) is in the denominator of the equations for a, b, and c.
12 x 100 x T+15 x 100 x T+37 x 100 x T+1750=TT=3.66
Then, plug this value of T into the equations for a, b, and c
Solution 2:
It seems your equations actually have 4 parameters, a, b, c and T, so you have a set of 4 linear equations with 4 parameters:
a + b + c - T = -1750
100 * a - 12 * Y = 0
100 * b - 15 * Y = 0
100 * c - 37 * Y = 0
You can solve this using the coefficients in a matrix:
import numpy as np
a = np.array([[1., 1., 1., -1.],
[100., 0, 0, -12.],
[0, 100., 0, -15.],
[0, 0, 100., -37.]])
b = np.array([-1750., 0, 0, 0])
If there is an analytical solution, you can use
res = np.linalg.solve(a, b)
# res: [ 583.33333333 729.16666667 1798.61111111 4861.11111111]
Otherwise (or for a more general case) you can approximate a solution using least-squared algorithm
res, err, _, __ = np.linalg.lstsq(a, b)# res: [ 583.33333333 729.16666667 1798.61111111 4861.11111111]
Post a Comment for "Optimize Common Parameters Across Several Equations Using Least Squares In Python"