I have recently started using python scripting, but have come across a problem when trying to plot a simple graph. It is supposed to produce a Mohr's Circle, but I am definitely missing something. This is the script I have at the moment: Any help would be greatly appreciated!
import math
import numpy as np
import matplotlib.pyplot as plt
%pylab inline
# max = maximum principal stress
# min = minimum principal stress
# x_norm = normal stress in x-direction
# y_norm = normal stress in y-direction
# t = shear stress
x_norm = -60
y_norm = 50
t = 50
R = math.sqrt(((x_norm - y_norm)/2)**2 + t**2)
print R
max = (x_norm + y_norm)/2 + R
min = (x_norm + y_norm)/2 - R
print max
print min
theta = 0.5 * math.atan((2*t)/(x_norm - y_norm))
print theta
aver = (x_norm + y_norm)/2
print aver
x = (min, max, x_norm, y_norm)
y = (math.sqrt(((x_norm - y_norm)/2)**2 + t**2))
plt.subplot(1,2,1)
plt.plot(x,y)
plt.show()
I have tried changing it, but get an error on the last part.
import math
import numpy as np
import matplotlib.pyplot as plt
%pylab inline
# max = maximum principal stress
# min = minimum principal stress
# x_norm = normal stress in x-direction
# y_norm = normal stress in y-direction
# t = shear stress
x_norm = -60
y_norm = 50
t = 50
R = math.sqrt(((x_norm - y_norm)/2)**2 + t**2)
print R
max = (x_norm + y_norm)/2 + R
min = (x_norm + y_norm)/2 - R
print max
print min
theta = 0.5 * math.atan((2*t)/(x_norm - y_norm))
print theta
aver = (x_norm + y_norm)/2
print aver
def circle(x_norm, y_norm, t):
x = (min, max, x_norm, y_norm)
y = (math.sqrt(((x_norm - y_norm)/2)**2 + t**2))
plt.subplot(1,2,1)
plt.plot(x,y)
plt.show()
circle(rad,x,y,np.linspace(-100,100,500))
print("Done")
NameError Traceback (most recent call last)
<ipython-input-5-0b893be1e1e8> in <module>()
35 plt.show()
36
---> 37 circle(rad,x,y,np.linspace(-100,100,500))
38 print("Done")
NameError: name 'x' is not defined