Prev: request for an algorithm or code
Next: struct_ array
From: Anna Kaladze on 29 Jul 2010 00:26 Dear all, I am new to MATLAB and to programming, and I need to solve quite a complex model, but it is mainly based on an algorithm which I have little clue how to program and which I will describe below via a simple example. If someone can help me with the code how to program it in MATLAB, that will be so great. Thanks a lot in advance. So, Step1: Define a guess vector, vector_guess = (x1_guess, x2_guess). Say, x1_guess = 10, x2_guess = 20. Step 2. Based on the vector_guess, calculate a new feedback vector via a series of equations and operations. Say, vector_feedback = (x1_feedback, x2_feedback) = (12, 25). Define a vector diff as a percentage difference between the guess vector and the feedback vector for the current iteration. So, diff = (0.2, 0.25). Then update vector_guess for the next iteration according to the rule: vector_guess*(1 + diff/q), where q is a positive integer (say q =9) and repeat the process until the diff vector <= 0.01. That is, I need to update the guess vector by a factor that depends on the discrepancy between the guess and feedback of the previous iteration. Once the discrepancy is within some tolerance, I need to exit the iterations. So, in my dummy “notations” it goes something like this (this example might not work as it is just an example, but I need to learn how to properly program it): vector_guess = (x1_guess, x2_guess) y1 = x1_guess + x2_guess y2 = x2_guess^2 + x1_guess y = y1 - x1^2 - x1 z = y2^2 - x2 - x2^2 x1_feedback = the value of x1 which maximizes y with respect to x1 x2_feedback = the value of x2 which maximizes z with respect to x2 vector_feedback = (x1_feedback, x2_feedback). And then keep updating vector_guess until the “equilibrium” is reached. I have no clue how this can be programmed. Please help. Thanks a lot! Anna.
From: Torsten Hennig on 28 Jul 2010 22:53 > Dear all, > I am new to MATLAB and to programming, and I need to > solve quite a complex model, but it is mainly based > on an algorithm which I have little clue how to > program and which I will describe below via a simple > example. If someone can help me with the code how to > program it in MATLAB, that will be so great. Thanks a > lot in advance. > So, > Step1: Define a guess vector, vector_guess = > (x1_guess, x2_guess). Say, x1_guess = 10, x2_guess = > 20. > Step 2. Based on the vector_guess, calculate a new > feedback vector via a series of equations and > operations. Say, vector_feedback = (x1_feedback, > x2_feedback) = (12, 25). > Define a vector diff as a percentage difference > between the guess vector and the feedback vector for > the current iteration. So, diff = (0.2, 0.25). > Then update vector_guess for the next iteration > according to the rule: > vector_guess*(1 + diff/q), where q is a positive > e integer (say q =9) and repeat the process until the > diff vector <= 0.01. That is, I need to update the > guess vector by a factor that depends on the > discrepancy between the guess and feedback of the > previous iteration. Once the discrepancy is within > some tolerance, I need to exit the iterations. > So, in my dummy “notations” it goes > something like this (this example might not work as > it is just an example, but I need to learn how to > properly program it): > vector_guess = (x1_guess, x2_guess) > y1 = x1_guess + x2_guess > y2 = x2_guess^2 + x1_guess > y = y1 - x1^2 - x1 > z = y2^2 - x2 - x2^2 > x1_feedback = the value of x1 which maximizes y with > respect to x1 > x2_feedback = the value of x2 which maximizes z with > respect to x2 > vector_feedback = (x1_feedback, x2_feedback). > And then keep updating vector_guess until the > “equilibrium” is reached. I have no clue > how this can be programmed. Please help. > Thanks a lot! > Anna. What is the final aim of your algorithm ? Maybe you can find specialized MATLAB routines that do the job for you. Best wishes Torsten.
From: Anna Kaladze on 29 Jul 2010 03:18 Torsten Hennig <Torsten.Hennig(a)umsicht.fhg.de> wrote in message <1672989918.21168.1280386468043.JavaMail.root(a)gallium.mathforum.org>... > What is the final aim of your algorithm ? > Maybe you can find specialized MATLAB routines > that do the job for you. > > Best wishes > Torsten. -------------------------------------------------- Hi Thorsten, Thanks a lot for your reply. This is to solve a complex macroeconomic problem which consists of a lot of time-dependent non-integral equations. I used to write macro’s in Excel and use its Solver to crack problems like this (Gauss-Seidel e.g.,), but as you know it often is more efficient to do programming of these sort of things in MATLAB. Looping takes forever, but I have heard that a commands like “count=0 and while” help to crack the problem really fast. I tried a bunch of simultaneous equations solving techniques in Mathematica but it takes a lot of time and thus not efficient. If I only could know how to program my example algorithm, that would do a trick fine. Essentially, in equllbrium, x1_guess and x2_guess should be such that all equations "clear" (otherwise it is not equllbrium). Thanks again.
From: Torsten Hennig on 28 Jul 2010 23:39 > Torsten Hennig <Torsten.Hennig(a)umsicht.fhg.de> wrote > in message > <1672989918.21168.1280386468043.JavaMail.root(a)gallium. > mathforum.org>... > > What is the final aim of your algorithm ? > > Maybe you can find specialized MATLAB routines > > that do the job for you. > > > > Best wishes > > Torsten. > -------------------------------------------------- > Hi Thorsten, > Thanks a lot for your reply. This is to solve a > complex macroeconomic problem which consists of a lot > of time-dependent non-integral equations. I used to > write macro's in Excel and use its Solver to > crack problems like this (Gauss-Seidel e.g.,), but as > you know it often is more efficient to do programming > of these sort of things in MATLAB. Looping takes > forever, but I have heard that a commands like > “count=0 and while” help to crack the > problem really fast. I tried a bunch of simultaneous > equations solving techniques in Mathematica but it > takes a lot of time and thus not efficient. If I only > could know how to program my example algorithm, that > would do a trick fine. Essentially, in equllbrium, > x1_guess and x2_guess should be such that all > equations "clear" (otherwise it is not equllbrium). > Thanks again. So you have a system of algebraic equations to solve ? Or a system of ordinary differential equations ? Or do you have to optimize an objective function ? Best wishes Torsten.
From: Anna Kaladze on 29 Jul 2010 04:58
> > So you have a system of algebraic equations to solve ? > Or a system of ordinary differential equations ? > Or do you have to optimize an objective function ? > > Best wishes > Torsten. -------------- Hi Torsten, The model has a mix of equations, which give rise to a number of functions which needed to be maximized. Briefly, by assumption, an “agent” takes certain values as given and does his maximization exercises (Much like you and I go to the supermarket and take all the prices there as given and decide "optimally" what to buy). But aggregated across many agents, those exercises affect the state of the economy, which require the agents to re-optimize ande the process continues until the equillbrium is reached (all equations clear and agents have no further incentives to reoptimize (or even if they, the arrive at the same vakues as before, so the aggregate economy’s state is not affected). That is, what everyone buys at the end, determines the new set of prices in the supermarkets, which you and I again take as given in our optimization execrise. In my model, many integrals are mathematically simply not integrable. If I assume very simple functions, they are, but the analytical solutions take several pages in length still. As for the maximization, I can of couse find the first/derivatives and sent them equal to zero and combine those with other equations and solve everything simultaneously), but the functions are so complex and they are “nearly” flat along large intervals. The shapes of the functions are extremely sensitive to the parameters of the model. Importantly, there are plenty of local maxima. All I need is to program the above example. The rest I hope to figure out myself (and I need global maximum). Of course, one wayb to ensure the global maxima is to predefine a range x1 and make sure y is evaluated at all those x1 points, and then tha best is chosen. But I am not worried about it at the moment. All I need is when I define a guess vector, the program to iterate until the feedback and the guess vectors are "equal". Preferably using “count” and “while” functions please. The example is again: vector_guess = (x1_guess, x2_guess) y1 = x1_guess + x2_guess y2 = x2_guess^2 + x1_guess y = y1 - x1^2 - x1 z = y2^2 - x2 - x2^2 x1_feedback = the value of x1 which maximizes y with respect to x1 x2_feedback = the value of x2 which maximizes z with respect to x2 vector_feedback = (x1_feedback, x2_feedback). The above procedure needs to continue until the percentage difference between x1_feeback and x1_ guess (and also x2_feedback and x2_guess) <=0.01. That is all I need. Thanks again. |