How to solve system of 3 non linear equations using fsolve, provided that all the three equations have 1 by 15 matrix terms in it.

9 views (last 30 days)
function F = myfun(E)
P = linspace(1,60,15);
F(1) = (((E(1)-2*E(2))*(3-2*E(1)^2))./(((1-E(1)-E(3))*...
((2-2*E(1)+E(3))^2))*(P.^2)))-Kp1;
F(2) = (((E(2))*(E(2)-E(3)))/((-2*E(2)+E(1))^2))-Kp2;
F(3) = (((E(3))*(E(3)-2*E(1)))/((1-E(1)-E(3))*(E(2)-E(3))))-Kp3;
end
This is my function file .Here Kp1,Kp2,Kp3 are matrix of dimension 1 by 15(.mat file uploaded)
For each P, we have different values of Kp1,Kp2,Kp3. For each P we have to solve the three non linear equations to get E1,E2 and E3.
I am using the below code,
E0 = [0.03 2.0123e-04 2.1234e-04];
options = optimoptions('fsolve','Display','iter',...
'Algorithm','levenberg marquardt',...
'MaxIter',2700,'MaxFunEvals',3000);
[E,fval] = fsolve(@myfun,E0,options)
Problems faced
1.) How to find a feasible solution with E1 E2 and E3 being positive numbers.
2.) For each P, there arise a difficulty in guessing the initial values of E1 E2 E3 each time.
3.) Is it possible to get all the 15 values of E1 E2 and E3 with a single execution?

Accepted Answer

Matt J
Matt J on 29 Oct 2015
Edited: Matt J on 29 Oct 2015
1.) How to find a feasible solution with E1 E2 and E3 being positive numbers.
If the E(i) are supposed to be positive, you need to use a constrained solver like LSQNONLIN. In fact, you might even consider using FMINCON, so that you can constrain the denominator expressions like ((-2*E(2)+E(1))^2)) to stay away from zero
2.) For each P, there arise a difficulty in guessing the initial values of E1 E2 E3 each time.
Since it is a small problem (only 3 variables) and since myfun is very vectorizable, you could do an initial numerical search over some reasonable sized grid of E1,E2,E3 values, e.g.,
[E1,E2,E3]=ndgrid(0:100);
values = abs(myfun(E1,E2,E3));
[~,i]=min( values(:) );
E_initial=[E1(i), E2(i), E3(i)];
3.) Is it possible to get all the 15 values of E1 E2 and E3 with a single execution?
Yes, by rewriting myfun as a function of 3*15=45 variables and similarly returning 45 equation values F(i). However, there's no reason to prefer a simultaneous solution, as far as I can see. It is much better to decompose optimization problems into smaller ones when you can.
  6 Comments
Alpesh Mor
Alpesh Mor on 10 Nov 2015
I have only learned the basic task (Matrices,Vectors,Optimization) functions in Matlab. May be you can guide me with some web link to run my code on a simulated case.
One more thing Matt...I am trying to run my Matlab files on another desktop. I have Matlab version 2015b and the desktop has Matlab version R2012a.All the files are .m files, but when i try to open these files in desktop it shows an error,
Undefined function 'uiopen'for the input arguments of type 'char'.
Can you help me with this too?
Matt J
Matt J on 10 Nov 2015
Edited: Matt J on 11 Nov 2015
If you pick some hypothetical set of values E1, E2,E3, you can then use your equations to calculate simulated Kp1, Kp2, Kp3. Then, you can use your code to try to recover the true, known E values given only the simulated Kp values. Note also that the grid-search procedure that I mentioned in my answer (and which you accepted) should be giving you an idea of where the global minimum lies and whether F(1), F(2), F(3) are close to zero there.
As for the thing with uiopen, I would try re-installing MATLAB, and talk to tech support if you continue to get the same error.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!