Sohee Dad
Sohee Dad

Reputation: 1

How could I fix the problem in my python code (array and plot)?

import numpy as np
import matplotlib.pyplot as plt

Pa00 = 100.0  # systemic arterial pressure
Pic00 = 9.5   # intracranial pressure
Pc00 = 25.0   # capillary pressure
Pvs00 = 6.0   # dural sinus pressure
Ca00 = 0.15   # arterial compliance
Rvp = 0.068   # resistance of venous plexus
CBFTo = 10.5 + 2.0   # total CBF of supine state
CBFv = 2.0      # vertebral vein part CBF of supine state
CBFj = CBFTo - CBFv     # jugular vein part CBF of supine state
CVP = 2.0    # central venous pressure
Q_normal = 12.5  # flow rate, ml/sec
unit_R = R_comp * 3.0   # arterial segment resistance
unit_C = 0.1    # arterial segment capacitance

Pvc = np.empty(22, dtype=float)
for i in range(1, 23):
    if i < 10:
        Pvc = Pa00 - i * unit_R * Q_normal
    elif i > 13 & i < 23:
        Pvc = CVP + i * R_comp * CBFj
    elif i == 10:
        Pvc = Pvc[8] - unit_R * Q_normal
        Pvc = Ca00 * (Pvc - Pic00)
    elif i == 11:
        Pvc = Ca00
    elif i == 12:
        Pvc = Pic00
    elif i == 13:
        Pvc = Pvs00
    print("{} {}".format(i, Pvc))
    
plt.plot(i, Pvc)
plt.show()

after running the above code, i got the result of 'print'.

1 99.95142857142856
2 99.90285714285714
3 99.85428571428571
4 99.80571428571429
5 99.75714285714285
6 99.70857142857143
7 99.66
8 99.61142857142858
9 99.56285714285714
10 2.136
11 2.1496
12 9.5
13 6.0
14 2.1904000000000003
15 2.204
16 2.2176
17 2.2312000000000003
18 2.2448
19 2.2584000000000004
20 2.2720000000000002
21 2.2856000000000005
22 2.2992000000000004

but i cannot get the result of plot. Is there any problem about 'array' or 'plot'? For several days, i was stuck in this problem.

Could you please let me know the solution about this problem?

Upvotes: 0

Views: 65

Answers (1)

Jordi Pastor
Jordi Pastor

Reputation: 174

you are actually assigning new values to Pvc variable instead of allocating it in the array. Use Pvc[index] = ... to assign it to a specific index.

Also, you need to record succession of i values in an array or generate a new array (e.g. np.arange(22)) else i will just contain it's most recent value (integer). In any case, you can get the same result omitting the x-val array in plot function (e.g plt.plot(Pvc))

Upvotes: 1

Related Questions