Question

Python code file PLEASE!!

b.) Write a program that uses FSOLVEO to solve the Rolling Wheel Dynamics – impending slip problem shown on Canvas. You MUST17-94. The tire has a weight of 30 lb and a radius of gyration of kg = 0.6 ft. If the coefficients of static and kinetic fricFind the value of theta where the wheek is fixin to slip (impending slip). W Given W.sin(theta) - F = “. gc N - W.cos(theta)

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For no-slip condition:

Rewriting the given equations:

W .sin(0) – F-.ka. ag = 0

N – W.cos(0) = 0

gc

ag -r.a=0

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 F , N , a_G and \alpha , respectively. The second set of numbers would be the known parameters, which are W , \theta , r , k_G , gc and \mu_s .

I = {F Naga

and

W = 30,0 = 12°, r = 1.5, kg = 0.8, gc = 32.2, js = 0.25.

These are to be sent to the function through fsolve() using "args" feature.

Initial guess asked to be taken is F=0, N = 0, ag = 0, a = 0 .

,{0 0 0 0} = 1 =.

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:

array( 1.38128182, 29.34442802, 5.21218062, 3.47478708])

= £ = ( 1,38 29.34 5.21 3.47 .

-------------------------------------------------

Impending slip:

Now, in the case of impending slip, the value of inclination \theta is also taken as a variable, which was earlier taken as a parameter in the "args" variable. And an additional equation F=MzN gets involved, which can be rewritten as F -M N = 0 .

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 \theta 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:

array( 4.97307536, 19.89230145, 18.76558906, 12.51039271, 48.46505515)

x= 4.97 19.89 18.77 12.51 48.46.

(Here, \theta would be in degrees, because the value is converted to radians inside the function.)

Now, let us consider varying \mu from 0.1 to 0.85 with a step-size of 0.05

Therefore, the number of steps would be

0.85 – 0.1 0,05 15.

And since the number of points would be one number more than the number of steps, the number of steps would be 15+1= 16.

In order to generate an array of points starting from 0.1 and ending at 0.85 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 \mu values to fsolve() to get the solution, and ultimately the corresponding \theta 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.

Plot of ramp-angle vs coefficient of friction for impending slip Inclination (6) in degrees 01 02 07 0.8 03 04 05 06 Coeffici

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.

Plot of ramp-angle vs coefficient of friction for impending slip Inclination (6) in radians 01 02 07 0.8 03 04 05 06 Coeffici

------------------------------------------------------------------------------------------

Add a comment
Know the answer?
Add Answer to:
Python code file PLEASE!! b.) Write a program that uses FSOLVEO to solve the Rolling Wheel...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT