Python program , getting error can't multiply sequence bynon-int of type 'float' on line Z = f(x,l)
Question:
Python program , getting error "can't multiply sequence bynon-int of type 'float'" on line Z = f(x,l)
I am trying to plot
from mpl_toolkits.mplot3d import Axes3D
import math
import cmath
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator,FormatStrFormatter
from numpy.linalg import inv
import scipy.linalg
from scipy.linalg import lu_factor, lu_solve
from numpy import pi, sin, cos, mgrid, log
from mpl_toolkits.mplot3d import Axes3D
from scipy.interpolate import interp1d
########################################################################################################################
# Question 1
To = 25
alpha = 2
l = (4,5,6,7,8)
tao = (0.405, 0.633, 0.912, 1.241, 1.621)
t = (0, 0.101, 0.203, 1.241,8.105) # (0,tao/4,tao/2, tao,5*tao)
#def f(x, y):
# return (25/2)*(25/2)*(cos((2*pi*x)/l))*exp(-t)
x = (1,2,3,4,5)
def f(x, l):
return(25/2)+(25/2)*(cos((2*3.14159*x)/l))*np.exp(-t)
y = [1,2,3,4,5]
X, Y = np.meshgrid(x, y)
Z = f(x,l) #(12.5, 3.359, 4.245, 10.693, 12.499)
fig = plt.figure()
ax = plt.axes(projection='3d')
surf = ax.plot_surface(X, Y, Z, cmap=cm.coolwarm, linewidth=0,antialiased=False) # , 50, cmap='binary')
ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('T');
ax.view_init(60, 35)
fig
# Plot the surface.
# linewidth=0, antialiased=False)
# Customize the z axis.
ax.set_zlim(0, 50)
ax.zaxis.set_major_locator(LinearLocator(10))
ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
# Add a color bar which maps values to colors.
fig.colorbar(surf, shrink=0.5, aspect=5)
plt.show()