How to use fsolve with a function of multiple outputs and inputs.

25 Ansichten (letzte 30 Tage)
Ethan Goode
Ethan Goode am 22 Jul. 2020
Bearbeitet: Ayush Gupta am 10 Sep. 2020
Hello all,
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;
end
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?
Thanks,
E

Antworten (1)

Ayush Gupta
Ayush Gupta am 10 Sep. 2020
Bearbeitet: Ayush Gupta am 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.

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by