How to use fsolve with a function of multiple outputs and inputs.
24 次查看(过去 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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Surrogate Optimization 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!