-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathp2e.py
More file actions
38 lines (33 loc) · 799 Bytes
/
p2e.py
File metadata and controls
38 lines (33 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Dec 8 12:51:11 2019
@author: xiaoshiguo
"""
import numpy as np
def v0(a,r,v_0,v_1):
if a == 1:
v_0 = 1+r*(1/3*v_0+2/3*v_1)
else:
v_0 = 4+r*(1/2*v_0+1/2*v_1)
return v_0
def v1(a,r,v_0,v_1):
if a == 1:
v_1 = 3+r*(1/4*v_0+3/4*v_1)
else:
v_1 = 2+r*(2/3*v_0+1/3*v_1)
return v_1
v_0 = 0
v_1 = 0
iteration = 100
for i in range(1,iteration):
v_0_t = np.maximum(v0(1,0.75,v_0, v_1), v0(2,0.75,v_0,v_1))
v_1_t = np.maximum(v1(1,0.75,v_0, v_1), v1(2,0.75,v_0, v_1))
v_0 = v_0_t
v_1 = v_1_t
print("v_0 is", v_0, "and v_1 is", v_1)
v01 = v0(1,0.75,v_0, v_1)
v02 = v0(2,0.75,v_0,v_1)
v10 = v1(1,0.75,v_0, v_1)
v12 = v1(2,0.75,v_0, v_1)
print(v01, v02, v10, v12)