janboone / applied-economics

course material for the course applied economics
17 stars 21 forks source link

Question regarding notebook assignment #20

Closed lindapelzer closed 3 years ago

lindapelzer commented 3 years ago

I have a question about the last question of elastic demand and supply (part of The Market), in which I get a little weird answer for the price. When I change the value of x0 in fsolve (starting estimate for roots, of which there can be more), I get different answers, e.g. when entering 10 or 40, I get price of 10 or 40 respectively and when entering for example 50, I get price of 2250. I succeeded in making the graph and it looks like the supply and demand curve cross at a price of about 125. Should I then just set x0 = 125? Or how would you know which x0 to use?

janboone commented 3 years ago

excellent question! We will talk about this tomorrow.

Your code is fine. If you use an initial value of 120 in the fsolve, you get the answer that you would expect.

The problem is numerical here. As we work with (only) 1000 agents, the functions for demand and supply are not perfectly "smooth" (you can see this in your graph). fsolve uses derivatives to find the point where demand_minus_supply equals 0. As the function is not smooth, these derivatives can go "all over the place", especially when the starting point is far from the point where the function equals 0.

In situations like this you can use the figure to find a starting point close to the solution you are trying to find.