For no-slip condition:
Rewriting the given equations:
Code for this function in Python:
Firstly, the required library files are to be imported.
from scipy.optimize import fsolve
from scipy import sin,cos,radians
Code for the function:
def equations_1(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
W,theta,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha]
return f
This takes two sets of numbers as input. The first set of numbers would be the unknowns of the above functions, which are , , and , respectively. The second set of numbers would be the known parameters, which are , , , , and .
and
These are to be sent to the function through fsolve() using "args" feature.
Initial guess asked to be taken is .
.
So, we add these two variables with the content as shown below.
args=(30, 12, 1.5, 0.8, 32.2, 0.25, )
initial_guess=[0, 0, 0, 0]
Now in order to solve the equations using fsolve(), we finally add this line to the code:
fsolve(equations_1,initial_guess,args=args)
By putting together the full code, we get
from scipy.optimize import fsolve
from scipy import sin,cos,radians
def equations_1(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
W,theta,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha]
return f
args=(30, 12, 1.5, 0.8, 32.2, 0.25, )
initial_guess=[0, 0, 0, 0]
fsolve(equations_1,initial_guess,args=args)
And the output it would generate would be:
-------------------------------------------------
Impending slip:
Now, in the case of impending slip, the value of inclination is also taken as a variable, which was earlier taken as a parameter in the "args" variable. And an additional equation gets involved, which can be rewritten as .
Therefore, the function needs to be slightly modified, as shown below.
def equations_2(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
theta=x[4]
W,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha,
F-mu_s*N]
return f
And the args variable would now contains no more the value, as it is now a variable. So, the args variable is to be slightly modified, as shown below.
args=(30,1.5,0.8,32.2,0.25,)
And the initial guess should have five values now, and initial values this time are taken as the array of ones, as shown below.
initial_guess=[1,1,1,1,1]
(Note: Any initial value is taken to attempt for the solution, and in general, the more close the initial guess to the actual solution, the more quickly the solution would converge, and sometimes there might be no solution possible to the set of functions, in which case fsolve() cannot solve, and in some other times it might be possible that there are multiple solutions that satisfy the equations, in which case the solution fsolve() converges to, depends on what initial guess is passed to it.)
By putting together the full code (along with the fsolve() command), we get
from scipy.optimize import fsolve
from scipy import sin,cos,radians
def equations_2(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
theta=x[4]
W,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha,
F-mu_s*N]
return f
args=(30,1.5,0.8,32.2,0.25,)
initial_guess=[1,1,1,1,1]
fsolve(equations_2,initial_guess,args=args)
And the output it would generate would be:
.
(Here, would be in degrees, because the value is converted to radians inside the function.)
Now, let us consider varying from to with a step-size of
Therefore, the number of steps would be
.
And since the number of points would be one number more than the number of steps, the number of steps would be
In order to generate an array of points starting from and ending at with the number of points being 16, linspace command of scipy is used, as shown below.
from scipy import linspace
stepsize=0.05
number_of_steps=(0.85-0.1)/stepsize
number_of_points=int(number_of_steps)+1
mu_values=linspace(0.1,0.85,number_of_points)
Now, an empty list is assigned to the variable 'theta_values', and a for-loop is made which can send each of the values to fsolve() to get the solution, and ultimately the corresponding value, which is the fifth (or last) value of the solution, with the index of 4, starting from 0, as shown below.
theta_values=[]
for i in mu_values:
args=(30,1.5,0.8,32.2,i,)
initial_guess=[1,1,1,1,1]
solution=fsolve(equations_2,initial_guess,args=args)
theta_value=solution[4]
theta_values.append(theta_value)
And, in order to plot, matplotlib is used, as shown below.
from matplotlib import pyplot as plt
plt.plot(mu_values,theta_values)
In order to add labels and title, some additional lines are used, as shown below.
plt.xlabel(r'Coefficient of friction ($\mu$)')
plt.ylabel(r'Inclination ($\theta$) in radians')
plt.title('Plot of ramp-angle vs coefficient of friction for
impending slip')
Finally, in order to show the plot (if already not shown), this line is used:
plt.show()
And so, the entire code can be put together as shown below:
from scipy.optimize import fsolve
from scipy import sin,cos,radians
from scipy import linspace
from matplotlib import pyplot as plt
def equations_2(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
theta=x[4]
W,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha,
F-mu_s*N]
return f
stepsize=0.05
number_of_steps=(0.85-0.1)/stepsize
number_of_points=int(number_of_steps)+1
mu_values=linspace(0.1,0.85,number_of_points)
theta_values=[]
for i in mu_values:
args=(30,1.5,0.8,32.2,i,)
initial_guess=[1,1,1,1,1]
solution=fsolve(equations_2,initial_guess,args=args)
theta_value=solution[4]
theta_values.append(theta_value)
plt.plot(mu_values,theta_values)
plt.xlabel(r'Coefficient of friction ($\mu$)')
plt.ylabel(r'Inclination ($\theta$) in degrees')
plt.title('Plot of ramp-angle vs coefficient of friction for
impending slip')
plt.show()
And the plot that it generates is shown below.
This plot has the theta values in degrees.
In order to get theta values in radians, the line
plt.plot(mu_values,theta_values)
needs to be changed to
plt.plot(mu_values,radians(theta_values))
and
plt.ylabel(r'Inclination ($\theta$) in degrees')
to
plt.ylabel(r'Inclination ($\theta$) in radians').
And so, the whole code to plot theta values in radians, would be:
from scipy.optimize import fsolve
from scipy import sin,cos,radians
from scipy import linspace
from matplotlib import pyplot as plt
def equations_2(x,*data):
F=x[0]
N=x[1]
a_G=x[2]
alpha=x[3]
theta=x[4]
W,r,k_G,gc,mu_s=data
f=[W*sin(radians(theta))-F-(W/gc)*a_G,
N-W*cos(radians(theta)),
F*r-(W/gc)*k_G**2*alpha,
a_G-r*alpha,
F-mu_s*N]
return f
stepsize=0.05
number_of_steps=(0.85-0.1)/stepsize
number_of_points=int(number_of_steps)+1
mu_values=linspace(0.1,0.85,number_of_points)
theta_values=[]
for i in mu_values:
args=(30,1.5,0.8,32.2,i,)
initial_guess=[1,1,1,1,1]
solution=fsolve(equations_2,initial_guess,args=args)
theta_value=solution[4]
theta_values.append(theta_value)
plt.plot(mu_values,radians(theta_values))
plt.xlabel(r'Coefficient of friction ($\mu$)')
plt.ylabel(r'Inclination ($\theta$) in radians')
plt.title('Plot of ramp-angle vs coefficient of friction for
impending slip')
plt.show()
And the plot is shown below.
------------------------------------------------------------------------------------------
Python code file PLEASE!! b.) Write a program that uses FSOLVEO to solve the Rolling Wheel...