0
$\begingroup$

I posted a question yesterday asking how I could get all the solutions to my system of 4 nonlinear equations with 4 unknowns. I gave up on this since it seems NSolve cannot manage equations with the fractional powers that I have. So I am using FindRoot with some initial value guesses. What I want to do is loop and calculate FindRoot for different parameter values. For instance, I create a list of assigned parameter values. I can find a solution to my system by assigning this list of parameters values. I want to do this but many times by changing the values of the parameter a from 0 to 2 with steps of 1/10. How could I do this?

I have seen a few questions in this forum that answer this but the examples are univariate.

This is my parameter list.

dat = {alpha -> 1./3., beta -> 1./3., sigma -> 1./3., gam -> 0.5, 
 psy -> 0.5, delta -> 0.5, vu -> 0.5, A -> 1./3., B -> 1./3., 
 C -> 1./3., Ls -> 10, T -> 10, mc -> 1.5};

This is my system of equations:

e1 = p2 - w^psy pw^gam ((psy/gam)^gam + (gam/psy)^psy) == 0;
e2 = Ls - (beta/w)^(alpha + sigma) (pw/(alpha (1 + a C r T)))^
  alpha (r/sigma)^sigma (w Ls delta + r T A) - (pw psy/w gam)^
  gam ((w Ls vu + r T B)/p2) == 0;
e3 = T - (sigma/r)^(alpha + beta) (w/beta)^
  beta (pw/(alpha (1 + a C r T)))^alpha (w Ls delta + r T A) == 0;
e4 = pw - (((((1 + a C r T) alpha)/pw)^(beta + sigma) (w/beta)^
       beta (r/sigma)^
       sigma (w Ls delta + r T A) +  ((w gam)/(psy pw))^
       psy ((w Ls vu + r T B)/p2)) mc (1 + 
     a C r T))/((((1 + a C r T) alpha)/pw)^(beta + sigma) (w/
       beta)^beta (r/sigma)^
     sigma (w Ls delta + r T A)  + ((w gam)/(psy pw))^
     psy ((w Ls vu + r T B)/p2) (1 + a C r T)) == 0;

And this is the calculation I do using the parameter list:

FindRoot[{e1, e2, e3, e4} /. dat, {{w, 0.5}, {r, 2}, {p2, 0.8}, {pw, 1.8}}]

How can I do this multiple times by using different values of a?

$\endgroup$
  • $\begingroup$ C symbol is reserved in Mathematica. $\endgroup$ – Mahdi Mar 26 '15 at 23:17
  • $\begingroup$ Sorry, I am a newbie, what does that mean, that C is used for special operations? $\endgroup$ – Goose Mar 26 '15 at 23:24
  • $\begingroup$ @Goose: In general, don't use uppercase initials on your symbols - you might clash with a built-in. In this case C is the default symbol for representation of constants. Try C=1 and see what happens... $\endgroup$ – ciao Mar 26 '15 at 23:48
1
$\begingroup$

So I think I found a way following this post: Find Roots in Do loop

I added these commands:

t = List[0, 0.5, 1, 1.5, 2]

Table[FindRoot[{e1, e2, e3, e4} /. 
  dat, {{w, 0.5}, {r, 2}, {p2, 0.8}, {pw, 1.8}}], {a, t}]

And it does calculate FindRoot over the different values of a.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.