How to use fsolve with a function of multiple outputs and inputs.
40 ビュー (過去 30 日間)
古いコメントを表示
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
0 件のコメント
回答 (1 件)
Ayush Gupta
2020 年 9 月 10 日
編集済み: Ayush Gupta
2020 年 9 月 10 日
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.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!