How to setup Optimisation ?
Show older comments
Hello,
I am trying to find multiple variables in equations. Suppose I have a cost factor, for different products, that changes annually. However, the form of the equation remains the same. The equation would be:
p=A^(x(1))*(1-B^(-x(2)))*(1-C*x(3))
The Variable A,B.C change with each year, but they are known and in an array. The same applies to p. Therefore my variables I am looking for are the ones in the x array. As example for the variables would be (where each row represent a year):
A=[1.25;1.25;1.25,1.15]
B=[1.5;1.4;1.3;1.2]
C=[0;0;1;1]
p=[1.53;1.51;1.45;1.21]
As for the Initial guess (for the optimisation) my guess would be for:
xo=[2;10;0.01]
How do i setup the optimisation to find the variables of x ? From the Matlab documentation it seems the LSQCURVEFIT is the approch I have to use, however I do not find any Information regarding the changing variables of A,B,C. I tried to solve this problem with the solve function, where i have 4 equations, but because p is rounded, it seems that the solve function is unable to solve for x.
Any help would be really appreciated and best regards
3 Comments
John D'Errico
on 30 May 2021
The reason you cannot use solve is you have 3 unknowns and effectively 4 equations. This is an overdetermined problem, and there will not be an exact solution.
As for what you mean by changing variables A,B,C, I have no clue. They don't change. They are fixed.
Perhaps your problem is you do not understand how to pass in those variables as vectors into your function. Learn about function handles and how to use them.
You have 4 equations to determine 3 parameters x(1),x(2) and x(3):
p - A.^x(1).*(1-B.^x(2)).*(1-C*x(3)) = 0
Since the number of equations is bigger than the number of unknowns, those problems are usually solved in the least-squares sense.
Use lsqnonlin to do this. In principle, you only have to include the arrays for p,A,B and C and the above equation in a function for the objective and to call lsqnonlin. The examples provided should show you how to proceed.
Richard H.
on 31 May 2021
Answers (0)
Categories
Find more on Nonlinear Least Squares (Curve Fitting) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!