Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Model of supply and demand
#1
Hello, can you help me figure out what is the problem in this code?
In a model of supply and demand,

the supply is:

Qs = P**a + P + 1

And the demand is:

Qd = 1/(0.5*P**2 + P)

I want to draw a sample of 1000 values for a assuming that a is a random variable which is uniformly distributed within interval [0.2,2.0]. Then I want to solve the equilibrium price for each by numerically finding the root of the excess demand function.

This is my code:
import numpy as np

a= np.linspace(0.2,2.0, num=1000)
z = 0.5  
    
    excess_demand = lambda W: 1/(z*P**2 +P)  - (P**(a) +P + 1)
    
    W, res = optimize.brentq(excess_demand, 1e-8, 1000.0, full_output=True)
    assert res.converged == True
    print(res)
    print(W) 
It appears to me an error? Can you tell me why?

This is the output:
Output:
excess_demand = lambda W: 1/(z*P**2 +P) - (P**(b) +P + 1) ^ IndentationError: unexpected indent
Reply
#2
Line 6 is indented. No need for the indentation, so it says unexpected indent
Reply
#3
And so what should I do?
Reply
#4
(Nov-17-2021, 06:54 PM)maeva Wrote: And so what should I do?
Read this. Especially the part about indentation.
Reply
#5
(Nov-18-2021, 08:50 AM)ibreeden Wrote:
(Nov-17-2021, 06:54 PM)maeva Wrote: And so what should I do?
Read this. Especially the part about indentation.

Thank you!
I wrote this code:
from scipy import optimize
import numpy as np

def main():
    a= np.linspace(0.2,2.0, num=1000)
    z = 0.5  
    
     
    excess_demand = lambda W: 1/(z*P**2 +P)  - (P**(a) +P + 1)
     
    W, res = optimize.brentq(excess_demand, 1e-8, 1000.0, full_output=True)
    assert res.converged == True
    print(res)
    print(W)
Now the problem is that P is undefined name (pyflakes E). I don't know how to solve it. Do you have any suggestions?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  model.fit and model.predict errors hatflyer 6 1,308 Nov-10-2023, 01:39 AM
Last Post: hatflyer
  FileNotFoundError: [Errno 2] No such file or directory: 'model/doc2vec.model/Articles Anldra12 10 5,773 Jun-11-2021, 04:48 PM
Last Post: snippsat
  auto supply values to a python script(function) from text file metro17 4 2,528 Oct-26-2019, 01:25 AM
Last Post: ichabod801
  Writing device driver to stop electric supply to any I/O port sumandas89 0 1,789 May-02-2019, 10:22 AM
Last Post: sumandas89

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020