tpemartin / 110-1-r4ds-main

MIT License
3 stars 73 forks source link

Exercise 5.3 equilibrium of demand and supply #62

Open tpemartin opened 2 years ago

tpemartin commented 2 years ago

Exercise 5.3 It is very common that economic model has some equilibrium condition as the intersection of two straight lines, like demand and supply. They can be expressed as: demand: p_d(q)=a+bq supply: p_s(q)=c+dq In equilibrium, (p, q) satisfies p_d(q)=p_s(q) and p=p_d(q)=p_s(q*).

If you solve for $q$ and $p$, q=(a-c)/(d-b) p=a+bq*.

  1. Run the following code and solve for equilibrium and save it in a list with two element names q_star and p_star. Each has its value in corresponding to q and p that your program solved.

    a=1; b=-3; c=0; d=1
  2. Create a function called solve_equilibrium so that the following code would work:

    
    a=1; b=-3; c=0; d=1
    equilibrium1 <- solve_equilibrium()
    print(equilibrium1)

a=2; b=-3; c=0; d=1 equilibrium2 <- solve_equilibrium() print(equilibrium2)

a=1; b=-3; c=0; d=1.5 equilibrium3 <- solve_equilibrium() print(equilibrium3)

raychiu135 commented 2 years ago

https://github.com/raychiu135/110-1-r4ds-main/blob/742de34e4f1aab7edeab1f5700fb6a80f8b5c8bf/exercise_5.3.rmd#L2

tpemartin commented 2 years ago

@raychiu135

  1. 'Error: object 'q_star' not found'. The element value of p_star need a name call on q_star but q_star object is not in the global environment.
raychiu135 commented 2 years ago

https://github.com/raychiu135/110-1-r4ds-main/blob/895ad0f4b7756af41d58d95e2f15cf31de36018c/exercise_5.3.rmd#L2

linttttt commented 2 years ago

https://github.com/linttttt/110-1-r4ds-main/blob/9174628cb663da6629080d65931afe76224c50e6/studyCH5(EX).Rmd#L102