Can Mathematica handle complex values in iterative mapping?

In summary: I need.In summary, I have no programming experience and trying to get mathematica to do what I need it to do is frustrating. I have the following functions that I need to iterate. For notational purposes, k[t+1] is the value of K in the next period. w is a parameter.k[t+1] = -x[t] - y[t] + wx[t+1] = k[t]*sqrt(y[t]/(-y[t] + w)) - y[t]y[t+1] = k[t]*sqrt(x[
  • #1
KevinL
37
0
I have no programming experience and trying to get mathematica to do what I need it to do is frustrating. I have the following functions that I need to iterate. For notational purposes, k[t+1] is the value of K in the next period. w is a parameter.

k[t+1] = -x[t] - y[t] + w
x[t+1] = k[t]*sqrt(y[t]/(-y[t] + w)) - y[t]
y[t+1] = k[t]*sqrt(x[t]/(-x[t] + w)) - x[t]

As I care more about the behavior of x and y, this system can be reduced to:

x[t+2] = (-x[t]-y[t]+w)*sqrt(y[t+1]/(-y[t+1] + w)) - y[t+1]
y[t+2] = (-x[t]-y[t]+w)*sqrt(x[t+1]/(-x[t+1] + w)) - x[t+1]

I have already found for what w the system becomes unstable by taking the Jacobian of the 3-system and seeing where it exceeds unity in absolute value. Now I just want to iterate the system and get some pretty graphs.
 
Physics news on Phys.org
  • #2
NestList will generate an iterative map for you. You can look up the documentation for that to get an idea how it works in general. For your specific example problem this might do:

k0 = .8; x0 = .7; y0 = .4; w = .3;
k[v_] := v[[1]]; x[v_] := v[[2]]; y[v_] := v[[3]];
f[t_] := {-x[t]-y[t]+w, k[t]*Sqrt[y[t]/(-y[t]+w)]-y[t], k[t]*Sqrt[x[t]/(-x[t]+w)]-x[t]}
r = NestList[f, {k0, x0, y0}, 2]

You should be able to check that those match the equations you gave.

So f inside the NestList is your function to repeatedly apply. You didn't provide starting conditions so I used {k0,x0,y0} as the initial value to start with and the final 2 says to only do two steps, just so you can see how it starts. You can increase the 2 once you believe it is working.

After you are done you will have a list of results, each containing {k,x,y} values.
If all you want is a list of results, each containing {x,y} values then you could do
Map[Rest,r]
and that would discard the k value from each result.

I am not certain where you want to go with this or how much of what I've written will be understandable to someone with no Mathematica background.

Study what I've written here, see if you can try it out. Carefully manually verify the calculations for a few steps with a few different starting values to try to expose any mistakes in this. If there are things you don't understand then provide more information about what you need explained and what you need this to do.

It might be less error prone to "scrape" the code off the screen and paste it into Mathematica than to try to type it back in because Mathematica is very demanding about () versus {} versus [] and capitalization.

If you get a list of real number pairs {x,y} then you can use ListPlot to directly provide your graphs from this.
 
Last edited:
  • #3
Simpler:

k0 = .8; x0 = .7; y0 = .4; w = .3;
f[{k_, x_, y_}] := {-x-y+w, k*Sqrt[y/(-y+w)]-y, k*Sqrt[x/(-x+w)]-x}
r = NestList[f, {k0, x0, y0}, 2]
 
Last edited:
  • #4
Sorry for getting back to you on this late, been busy!

For the most part this is working as I would like. I put in:

k0 = .6; x0 = .3; y0 = .1 ; w = 1;
f[{k_, x_, y_}] := {-x - y + w, k*Sqrt[y/(-y + w)] - y,
k*Sqrt[x/(-x + w)] - x}
r = NestList[f, {k0, x0, y0}, 100]
ListPointPlot3D[r]

The numbers converge to precisely what my math has told me they should converge to, and the graph it generates is decent. However, it would be better if I could see the dots generated in time rather than just all the dots plotted at the same time. Difficult to see behavior when they are all plastered on there at the same time.

X and Y denote production of 2 firms. I have also adapted this to handle 3 firms, so X, Y, and Z output (K is kinda a weird variable, but it helps to determine what the firms should do). The math tells me what it should converge to, but when I try to use the program to iterate the 3 firm case it outputs absurd answers, such as negative output and even complex valued output. The only thing I can reason for why its doing this is that it perhaps is not taking the values to enough significant figures.
 
  • #5
Hmm. For most of the similar models that I've been dealing with, it was possible to write the "reaction functions" (the functions I wrote in my first post) in such a way that you could actually have X in the next period determined by X in the last period. The test for stability of the continuously differentiable FUNCTION involved taking the Jacobian of the reaction functions and seeing if it passed unity in absolute value.

You cannot put my functions together in such a way that X in the next period is based on X in the last period. So perhaps I have a continuously differentiable MAP? The test for stability of a continuously differentiable map is slightly different, and perhaps if I use this test I can see why the 2 firm case is stable and the 3 firm case is not stable.

That is, if I am understanding the difference between a continuously differentiable function and continuously differentiable map.
 
Last edited:
  • #6
1. Your square roots and minus signs make it feasible and perhaps even easy to end up with complex values during your iterations. I can't say anything about whether your map is appropriate or not.

2. Users occasionally ask if they can't somehow slow Mathematica down and watch it plot one point at a time. There has been nothing in the past to make that easy, but there are a handful of things you might try. There is the PlotJoined->True option that you can add as an argument to your ListPlot. That will connect the points in order with line segments. I don't know that will help you enough. My simple experimentation with your equations shows wild behavior of the iterations, even if I use ListPlot[Map[Re,yourlist],PlotJoined->True] to only see the real components.

You might also explore Manipulate which is a new feature introduced in version 8 that might allow you to only plot points up to some boundary that you can select with a slider and see if you can figure out enough to be able to use that. That might involve the Manipulate containing your ListPlot containing a Take to extract the first part of of your list and the Manipulate control telling Take how many points to extract.

The older way of doing that was to make a large collection of plots, each with one more point than the last and then export the whole collection as a movie.

But doing things like this is perhaps more advanced than I expected you to be able to figure out how to implement.

From what you have written I'd probably look first at making certain your function is correct and only after that has been verified would I start trying to wrestle Mathematica to the ground.
 

1. What is an iterative map in Mathematica?

An iterative map in Mathematica is a function that repeatedly applies a rule or transformation to a starting value, creating a sequence of values. It is a powerful tool for exploring and visualizing mathematical concepts and systems.

2. How do I create an iterative map in Mathematica?

To create an iterative map in Mathematica, you can use the built-in function NestList, which takes a function and an initial value as arguments and generates a list of values by repeatedly applying the function to the previous value. You can also use the Nest function, which only returns the final value instead of the entire list.

3. Can I customize the iteration process in Mathematica?

Yes, you can customize the iteration process by specifying the number of iterations or using a stopping condition. For example, you can use the NestWhile function to stop the iteration when a certain condition is met, or use the NestList function with a third argument that specifies the number of iterations to perform.

4. What types of problems can be solved using iterative maps in Mathematica?

Iterative maps in Mathematica can be used to solve a wide range of problems in various fields of mathematics, such as dynamical systems, chaos theory, fractals, and numerical analysis. They can also be applied to real-world problems, such as optimization and simulation.

5. Are there any limitations to using iterative maps in Mathematica?

While iterative maps can be a powerful tool, they also have limitations. For example, the convergence of the iterates may depend on the initial value chosen, and some functions may not converge at all. It is important to understand the properties of the function and the starting value before using iterative maps in Mathematica.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
268
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
3K
  • Programming and Computer Science
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
12
Views
4K
  • Differential Equations
Replies
5
Views
661
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • Programming and Computer Science
Replies
2
Views
1K
Back
Top