I am very new to Mathematica, so please bear with me. I have looked up all I can without posting but now I am stuck.
The following is for context, so the code (inexpertly written) is easier to understand). In addition, I ended up writing very "long hand" so I could work out what is happening, I'd like to automate more if I can find the answer to my basic problem.
I am trying to set up a toy problem where someone is making a path of choices over 3 periods (think of them as consumption) to maximize a "welfare from consumption" function. Something you can think of as "price" can take different paths (very simply from the current price: stay the same, go lower, go higher) subject to a budget constraint. In the first period, the choice is a, in the second, it could be b1,b2, or b3, depending on price; if b1 happens, then in period 3, it can be c1,c2, or c3, or if b2 happens in can be c4,c5 or c6, etc.
I substitute in the budget constraint to eliminate the "c" variables, so I am left with choice variables a,b1,b2, and b3.
I have tried FindRoot and Nsolve (see my code below), but it really doesn't seem to work - possibly because the function is too nonlinear. For the equivalent 2-period problem, NSolve or FindRoot finds the solution very easily. So next, I tried to do the following: Given "a" find the optimal choices for b1 to b3, c1 to c9, and plug them into the welfare function. Then search for the "a" that maximizes the welfare function overall. But, although writing a user function for the first part is simple enough (fun[ai_] in the code), I am stuck on how to search for the maximizing "a". As you can see below, I tried something like FindMaximum, but this doesn't seem right (as I am unable to use my user-defined function in it).
Any help is greatly appreciated.