<jupyter_start><jupyter_text>[](https://mybinder.org/v2/gh/NumEconCopenhagen/NumEconNotebooks/master?urlpath=lab/tree/micro/01_Preferences.ipynb)  Setup<jupyter_code>%matplotlib inline
%load_ext autoreload
%autoreload 2

import matplotlib.pyplot as plt
plt.style.use('seaborn-whitegrid')
prop_cycle = plt.rcParams['axes.prop_cycle']
colors = prop_cycle.by_key()['color']
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection, Line3DCollection
import ipywidgets as widgets

import numecon.micro.consumption as consumption<jupyter_output><empty_output><jupyter_text>Static: Indifference curves and checks Using **analytical** expressions:<jupyter_code>consumer = consumption.ConsumerClass(preferences='cobb_douglas',alpha=0.1,beta=0.1,x1max=10,x2max=10)
fig,ax = consumer.figure()

# 45 degrees 
ax.plot([0,consumer.x1max],[0,consumer.x2max],'--',color="black",zorder=1,alpha=0.1)

# indifference curves
x1s = [2,4,6]
x2s = [2,4,6]
us = [consumer.utility(x1,x2) for x1,x2 in zip(x1s,x2s)]
[ax.plot(x1,x2,'ro',color='black') for x1,x2 in zip(x1s,x2s)]
[ax.text(x1*1.03,x2*1.03,f'u = {u:5.2f}') for x1,x2,u in zip(x1s,x2s,us)]
consumer.plot_indifference_curves(ax,us)

# checks
consumer.plot_monotonicity_check(ax,x1=x1s[1],x2=x2s[1])
consumer.plot_convexity_check(ax,u=us[0])<jupyter_output><empty_output><jupyter_text>Using **numerical** solution:<jupyter_code>consumer = consumption.ConsumerClass(preferences='cobb_douglas',alpha=0.1,beta=0.1,x1max=10,x2max=10)
fig,ax = consumer.figure()

# 45 degrees 
ax.plot([0,consumer.x1max],[0,consumer.x2max],'--',color="black",zorder=1,alpha=0.1)

# indifference curves
x1s = [2,4,6]
x2s = [2,4,6]
us = [consumer.utility(x1,x2) for x1,x2 in zip(x1s,x2s)]
[ax.plot(x1,x2,'ro',color='black') for x1,x2 in zip(x1s,x2s)]
[ax.text(x1*1.03,x2*1.03,f'u = {u:5.2f}') for x1,x2,u in zip(x1s,x2s,us)]
consumer.plot_indifference_curves(ax,us,numerical=True,only_dots=True)<jupyter_output><empty_output><jupyter_text>Interactive: Cobb-Douglas $$u(x_1,x_2) = x_1^{\alpha}x_2^{\beta}$$<jupyter_code>consumption.interactive_indifference_curves(preferences='cobb_douglas')<jupyter_output><empty_output><jupyter_text>Interactive: Constant Elasticity of Substitution (CES) $$u(x_1,x_2) = (\alpha x_1^{-\beta}+(1-\alpha)x_2^{-\beta})^{-1/\beta}$$<jupyter_code>consumption.interactive_indifference_curves(preferences='ces')<jupyter_output><empty_output><jupyter_text>Interactive: Perfect substitutes $$u(x_1,x_2) = \alpha x_1 + \beta x_2$$<jupyter_code>consumption.interactive_indifference_curves(preferences='perfect_substitutes')<jupyter_output><empty_output><jupyter_text>Interactive: Perfect complements $$u(x_1,x_2) = \min{\{\alpha x_1,\beta x_2}\}$$<jupyter_code>consumption.interactive_indifference_curves(preferences='perfect_complements')<jupyter_output><empty_output><jupyter_text>Interactive: Quasi-linear (log) $$u(x_1,x_2) = \alpha\log(x_1) + \beta x_2$$<jupyter_code>consumption.interactive_indifference_curves(preferences='quasi_log')<jupyter_output><empty_output><jupyter_text>Interactive: Quasi-linear (sqrt) $$u(x_1,x_2) = \alpha\sqrt{x_1} + \beta x_2$$<jupyter_code>consumption.interactive_indifference_curves(preferences='quasi_sqrt')<jupyter_output><empty_output><jupyter_text>Interactive: Concave $$u(x_1,x_2) = \alpha x_1^2 + \beta x_2^2$$<jupyter_code>consumption.interactive_indifference_curves(preferences='concave')<jupyter_output><empty_output><jupyter_text>Interactive: Quasi-quasi-linear $$u(x_1,x_2) = x_1^{\alpha} (x_2 + \beta)$$<jupyter_code>consumption.interactive_indifference_curves(preferences='quasi_quasi')<jupyter_output><empty_output><jupyter_text>Interactive: Saturated (non-montone) $$u(x_1,x_2) = -(x_1-\alpha)^2 - (x_2-\beta)^2$$<jupyter_code>consumption.interactive_indifference_curves(preferences='saturated')<jupyter_output><empty_output><jupyter_text>Save all figures<jupyter_code>consumption.interactive_indifference_curves_save(preferences='cobb_douglas')
consumption.interactive_indifference_curves_save(preferences='ces')
consumption.interactive_indifference_curves_save(preferences='perfect_substitutes')
consumption.interactive_indifference_curves_save(preferences='perfect_complements')
consumption.interactive_indifference_curves_save(preferences='quasi_log')
consumption.interactive_indifference_curves_save(preferences='quasi_sqrt')
consumption.interactive_indifference_curves_save(preferences='concave')
consumption.interactive_indifference_curves_save(preferences='quasi_quasi')
consumption.interactive_indifference_curves_save(preferences='saturated')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15371254884932697, 'fraction_numerical': 0.035822839774207554, 'mean_word_length': 12.960606060606061, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 53, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '13', 'dir': 'jupyter-structured-clean-dedup', 'id': '239579', 'license': 'MIT', 'n_tokens_mistral': 1923, 'n_tokens_neox': 1862, 'n_words': 167, 'path': 'micro/02_Preferences.ipynb', 'repo_name': 'Kristianuruplarsen/NumEconNotebooks', 'size': '4606'}