0

i am getting the error File "C:/Users/user/tensorEnv/project.py", line 27, in if N <= 100 : ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() how to fix this problem

import matplotlib.pyplot as plt
import numpy as np
r3=np.arange(1.11,10,0.1)
r1=1
r2=1.1
k=5
R1cond=3.36*10**(-3)
R2cond=(1/N)*(0.0727-(0.08/r3))
Rconv=(0.004)/(r3**2)
Rtotal=Rconv+R1cond+R2cond
qloss=975/Rtotal
t=176
Q=qloss*t
L0=[]
L0.append(Q)
L0=[x*10**(-3) for x in L0]
#E is the price of EDL in LBP/NW.h
#Eel is the electric price to pay
#t is the time of working hours of the furnace 22 business days
#E=Eel*qloss*t
L=[]
L1=[]
L2=[]
L3=[]
L4=[]
for N in L0:
        if N <= 100 :
                L.append(35*N)
        if N <= 300 and N > 100:
                L1.append( 55*N)
        if N <=400 and N > 300:
                L2.append(80*N)
        if N <= 500 and N > 400:
                L3.append(120*N)
        if N > 500 :
                L4.append(200*N)
plt.plot(L)
plt.plot(L1)
plt.plot(L2)
plt.plot(L3)
plt.plot(L4)
plt.show()
toni
  • 19
  • 1
  • 6
  • Welcome to stack overflow! Please take a moment and [edit] to include the full traceback(s) of your errors – G. Anderson Feb 05 '20 at 18:30
  • In the plotting error, you're trying to plot with a list of 100 x values (`r3`) and a single y value (`R1cond`), and matplotlib doesn't know how to handle that. What is your expected output from `plt.plot(r3,R1cond...`? – G. Anderson Feb 05 '20 at 18:32
  • a plot of the conduction, convection and total resistance versus the thickness of the insulation – toni Feb 05 '20 at 18:40
  • Yes, but specifically in the line mentioned, what would that first plot look like, with 100 values vs a single value? Should it be a flat line, a single point? The value of `R1cond` doesn't change or repeat with the values of `r3` so it's not clear what you're trying to do – G. Anderson Feb 05 '20 at 18:45
  • i solved this part i was plotting a straight line for R1cond and the others are in function of r3 and i think that python was expected to plot R1 in function of x i fixed it,can u help me with the second part? – toni Feb 05 '20 at 19:19
  • Please [edit] to include the full error traceback so that we can understand where the issue is occurring. Assuming it's on the lines that deal with `if Q <=..." please also provide the type and shape of `Q`, what you expect it to be and what you expect the output to be – G. Anderson Feb 05 '20 at 19:59
  • related?: https://stackoverflow.com/questions/10062954/valueerror-the-truth-value-of-an-array-with-more-than-one-element-is-ambiguous – David Cary Sep 15 '20 at 20:43

0 Answers0