How to use fsolve with a function of multiple outputs and inputs.
62 views (last 30 days)
I have a function that contains three sets of vectorized equations:
function [F, G, H] = ekmodelGen(p , x_ni, w)
global dni T L theta gam beta
F = (gam.*((dni.*((p.^(1-beta))*((w.^beta).')).').^-theta)*T)-p;
G =(T.'.*((1/p).'.*dni.*((p.^(1-beta))*((w.^beta).')).').^-theta)- x_ni;
H = ((x'*(w.*L))./L)-w;
And I want to solve F, G, and H simultaneously and recover p's, x_ni's, and w's with fsolve. For context, p is an nx1 vector, x_ni is an nxn matrix, and w is an nx1 vector. My issue is how to implement fsolve. I have the following code:
x0 = 0.5.*ones(1,24);
dni = ones(2);
T = ones(4,1);
L = ones(4,1);
theta = 4;
beta = 0.5;
gam = 1;
sol = fsolve(@ekmodelGen, x0);
This code should yield the a solution to the system where n =4. What do I need to modify to get fsolve to give me the solution. Is my intial guess, x0, coded incorrectly? Do I need to change the way my function is written? Am I not calling the function properly? Or all of the above?
Ayush Gupta on 10 Sep 2020
Edited: Ayush Gupta on 10 Sep 2020
fsolve() is not suitable for finding multiple solutions, except through the mechanism of running multiple times with different x0 until the number of distinct solutions found has accumulated to the number desired. After that you can use fsolve to solve with multiple variables and can leverage this post to use fsolve with multiple variables here.