MATLAB: Find optimized solution of linear system of equations

linear systemoptimized solution

I have this system of equations and I am willing to find the value of kp, ki, kp
0.1*kd +0.49 = 18;
0.04*kd +0.1*kp +21.6 = 121;
0.04*kd +0.1*ki +0.98 = 438;
1.96*(kd +kp)+ 0.04*ki = 1030;
1.96*ki = 1200;
and kp, ki, kd > 0
Using linsolve of the system, the answer was Inf for all.

Best Answer

Try this:
syms kd kp ki
Eq1 = 0.1*kd +0.49 == 18;
Eq2 = 0.04*kd +0.1*kp +21.6 == 121;
Eq3 = 0.04*kd +0.1*ki +0.98 == 438;
Eq4 = 1.96*(kd +kp)+ 0.04*ki == 1030;
Eq5 = 1.96*ki == 1200;
[A,b] = equationsToMatrix(Eq1,Eq2,Eq3,Eq4,Eq5);
Coeffs = lsqr(double(A), double(b));
kd = Coeffs(1)
ki = Coeffs(2)
kp = Coeffs(3)
producing:
kd =
912.95079751536
ki =
620.999261482952
kp =
-397.442602821135
The Symbolic Math Toolbox sorts the variables in lexicographical order, so kd>ki>kp, thus the ordering in the results.
Experiment to get the result you want.