Solving N non-linear equations using fsolve. How do I pass these equations into my function without typing them out individually?

3 次查看(过去 30 天)
Hello all,
I am currently working with the Eaton-Kortum Trade Model in MATLAB. In this model we have N countries, and wish to solve 2N + N^2 non-linear equations for equilibrium outcomes. I am working currently on an example with four countries, which means I will need to use fsolve to solve 24 equations. I understand that I could type all 24 equations individually, but what happens when we allow N to grow in the model (to better reflect what the world looks like)? If I wanted to consider trade between 10 countries I would have to type 120 equations seperatley! Luckily these equations take one of three forms.
N of the equations take the form: (gam.*((sum(Ti.*(dni.*(w(i).^(beta)).*(p(i))).^(1-beta)).^(-theta)).^(-1./theta))) - p(n);
N^2 of the equations take the form: Ti.*(gam.*dni.*(w(i).^(beta))*(p(i).^(1-beta))*(1./p(i))).^(theta) - (x(i));
N of the equations take the form: ((beta).*(sum(Ti.*(gam.*dni.*(w(i).^(beta))*(p(i).^(1-beta))*(1./p(i))).^(theta)*x(i)))) - (w(i).*Li)
Where our unknowns are w's, p's, and x's and everything else is given.
Is there a way for me to iteratively feed these equations into fsolve?
For example:
F(1) = (gam.*((sum(Ti.*(dni.*(w(i).^(beta)).*(p(i))).^(1-beta)).^(-theta)).^(-1./theta))) - p(1);
F(2) = (gam.*((sum(Ti.*(dni.*(w(i).^(beta)).*(p(i))).^(1-beta)).^(-theta)).^(-1./theta))) - p(2);
F(3) = (gam.*((sum(Ti.*(dni.*(w(i).^(beta)).*(p(i))).^(1-beta)).^(-theta)).^(-1./theta))) - p(3);
F(4) = (gam.*((sum(Ti.*(dni.*(w(i).^(beta)).*(p(i))).^(1-beta)).^(-theta)).^(-1./theta))) - p(4);
If there is not a way to do what I suggest how should I attempt to implement this?
  15 个评论
Walter Roberson
Walter Roberson 2021-8-21
It looks to me as if perhaps the poster deleted at least one of their comments, so I am not sure whether the code ended up working for them.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Surrogate Optimization 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by