问题
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 solve and three parameters to optimize:
a+b+c+1750=T
12=a/T*100
15=b/T*100
37=c/T*100
where I would like to find the optimal values of a,b, and c. Does anybody have a suggestion, perhaps using a least squares method? I am only familiar when there is but one equation to solve.
回答1:
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]
回答2:
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 = T
T = 3.66
Then, plug this value of T into the equations for a, b, and c
来源:https://stackoverflow.com/questions/50725425/optimize-common-parameters-across-several-equations-using-least-squares-in-pytho