Using "for" and "fsolve"
1 回表示 (過去 30 日間)
古いコメントを表示
I am trying to solve a system of two equations - two unknowns for several locations; 14 total; I tried to use for command but I only get an answer for the first element; any idea how to get answers for all locations? My code is below:
.......
function F = countries(x)
global beta qsi tau rho gamma theta g A B
F = [(beta*(1-x(1)-x(2))^-1)-(1-gamma)*A*[(theta*((A*x(1)*(1-gamma)+B*(x(2)^qsi)*qsi*(1-rho*gamma))^-1))+((1-theta)*(A*x(1)*(1-gamma)+B*(x(2)^qsi)*qsi)^-1)];
(beta*(1-x(1)-x(2))^-1)-(B*(x(2)^(qsi-1))*qsi)*[((1-rho*gamma)*theta*((A*x(1)*(1-gamma)+B*(x(2)^qsi)*qsi*(1-rho*gamma))^-1))+((1-theta)*(A*x(1)*(1-gamma)+B*(x(2)^qsi)*qsi)^-1)]];
.........
global beta qsi tau rho gamma theta g A B
% x(1) ............. one for each country
% x(2) ............. one for each country
beta = 1.924;
qsi = 0.71;
theta = 0.01;
g = 0.2;
A = 1;
B = 0.4505;
%load data
dataset = 'dataApr11.txt';
load(dataset);
for i = 1:14
itau(i,1) = dataApr11(i,3);
irho(i,1) = dataApr11(i,4);
igamma(i,1) = dataApr11(i,2);
x0 = [0.2; 0.25]*ones(1,14);
options=optimset('Display','iter');
[x,fval] = fsolve(@countries,x0,options)
W(i,1) = x(1,i)
Y(i,1) = x(2,i)
end
0 件のコメント
採用された回答
Andrei Bobrov
2011 年 5 月 3 日
can so
...
W = zeros(14,1);
Y = zeros(14,1);
x0 = [0.2; 0.25]*ones(1,14);
for i = 1:14
tau = dataApr11(i,3);
rho = dataApr11(i,4);
gamma = dataApr11(i,2);
[x,fval] = fsolve(@countries,x0,optimset('Display','iter'));
W(i) = x(1)
Y(i) = x(2)
end
...
0 件のコメント
その他の回答 (2 件)
Yoav Livneh
2011 年 5 月 3 日
Your initial guess x0 is the same for all iterations. I dont know what the "countries" function does, and how the other variables itau, irho and igamma are connected, but it looks like you're solving the same problem 14 times.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Particle & Nuclear Physics についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!