Solve equation using a loop
Afficher commentaires plus anciens
I have this code:
syms s1 s2 A1 A2 k1 k2 alpha delta;
capital1 = @(k) s1*A1*k1^alpha + (1-delta)*k1 == k1;
capital2 = @(k) s2*A2*k2^alpha + (1-delta)*k2 == k2;
kss1=solve (capital1,k1, 'IgnoreAnalyticConstraints',1)
kss2=solve (capital2,k2, 'IgnoreAnalyticConstraints',1)
But i would like to use a loop to do it, such as:
syms s(i) A(i) k(i) alpha delta;
for i=[1 2]
kss(i)=solve (s(i)*A(i)*k(i)^alpha + (1-delta)*k(i) == k(i),k(i), 'IgnoreAnalyticConstraints',1)
end
However, when i run that code, instead of giving me two 1x1 sym (kss1 and kss2), i end up with a 1x2 struct.
I have little experience using matlab, so i don't really know what the problem is or what I did wrong when writting the loop.
Thanks.
Réponses (1)
Torsten
le 16 Oct 2022
s*A*k^alpha + (1-delta)*k = k
-> s*A*k^alpha - delta*k = 0
-> k*(s*A*k^(alpha-1) - delta) = 0
-> k = 0 or k = (delta/(s*A))^(1/(alpha-1))
Catégories
En savoir plus sur Programming dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!