QuestionQuestion

Transcribed TextTranscribed Text

Exercise Aim: Get accustomed to basic one-dimensional methods for solving a non-linear equation I f (x) ≡ exp((x − 2) 2 ) − 2 − x g(x) ≡ exp((x − 2) 2 ) − 2 Task: 1. Solve f (x) = 0 by the bisection method with initial x L = 0.5 & x R = 1.5. You can use the SciPy root-finding package. 2.1. Solve x = g(x) by the fixed-point iteration with the updating rule xk+1 = g(xk ). Code the algorithm by yourself. Does this work? Explain why or why not. 2.2. Solve x = g(x) by the fixed-point iteration with the updating rule xk+1 = λk xk + (1 − λk )g(xk ) where λ0 = 1 & λk = 0.99λk−1 I Using matplotlib.pyplot, plot the convergent sequence (like what we saw in the lecture). (Adapted from Collard, Lecture Notes 5. ) Assignment: Cournot Duopoly Model Aim: Get accustomed to basic multi-dimensional methods for solving a system of non-linear equations. Vectorize the system. I Quantity competition by 2 firms i = 1, 2 I Inverse demand of a good: P(q) = q −1/α I Cost function: Ci(qi) = 1 2 ciq 2 i I Profit for each firm i: πi(q1, q2) = P(q1 + q2)qi − Ci(qi) I Assume c1 = 0.6 & c2 = 0.8 Task 1. Solve for equilibrium q ∗ i for i = 1, 2 and P(q ∗ 1 + q ∗ 2 ) with α = 1.5 by (1) Newton’s method: Code the algorithm by yourself. That is, analytically derive the Jacobian of the set of FOCs. (2) Broyden’s method: You can use the SciPy root-finding package. (3) Fixed-point iteration: Code the algorithm by yourself. Task 2. Solve the model for all α ∈ [1, 3] (construct grids) by Broyden’s method. Using matplotlib.pyplot, produce two plots with x-axis α & y-axes (i) q ∗ 1 , q ∗ 2 (ii) P(q ∗ 1 + q ∗ 2 ).

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

from numpy.linalg import norm          # matrix / vector norm
from numpy.linalg import inv            # inverse matrix
from numpy import matmul, array, linspace # matrix multiplication
from scipy.optimize import broyden1    # broyden method
import matplotlib.pyplot as pp

# Task 1:

# converts numpy column to list
def col2list(qq):
    return qq.transpose()[0].tolist()

# analytical jacobian
def Jac(qq,a):
    global c1, c2
    q1, q2 = tuple(col2list(qq))

    return array([[
       -c1 + ((q1 + q2) ** (-2 - 1 / a) * (q1 - a * q1 - 2 * a * q2)) / a ** 2,
       ((q1 + q2) ** (-2 - 1 / a) * (q1 - a * q2)) / a ** 2],
       [((q1 + q2)**(-2 - 1/a)*(-(a*q1) + q2))/a**2,
         -c2 + ((q1...

By purchasing this solution you'll be able to access the following files:
Ex1.py and Ex2.py.

$38.00
for this solution

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats