Brake Analysis II - Design and Costing:
Creating the Maple Package ' brake '
2000 Waterloo Maple
Note: This worksheet details the process required to convert the Brake Analysis Solution worksheet into a Maple package. The resulting 'brake' package is then incorporated into a dynamic Microsoft Excel 2000/Maple 6 worksheet; using the Maple 6 Add-in.
The required Maple code for creating the package "wrapper" is listed in black bold type.
Summary:
> restart;
The lines from brake to .. option package are all that are required on the 'top' wrapper.
> brake:=module(); test
This line defines the name of the module.
> export brake_analysis, bolt_analysis;
This defines which functions can be used by the user.
local clear_units, reset_units; This defines which functions can not be used by the user. They are only used internally by the package.
option package; This defines the module as a type "package".
Then the procedure declaration(s) are made for the functions in the package along with the required Maple code that defines the solution. brake_analysis:=proc(FORCE, MU); local X_16,Y_16,X_12,Y_12,X_13,Y_13,X_26,Y_26,X_36,X_34,X_25,Y_25,X_45,Eq1x,Eq1y,Eq1m,Eq2x,Eq2y,Eq2m,Eq3x,Eq3y,Eq3m,Eq4x,Eq5x,Eq5y,Eq5m,vars,eqs,soln,F_1,F_2,F_3,F_4,F_5,Max_force,mu,F; F:=FORCE; mu:=MU; Eq1x:=X_36-X_16-X_26=0; Eq1y:=-mu*X_36+Y_16+mu*X_26=0; Eq1m:=-880+250*Y_26+250*mu*X_36=0; Eq2x:=-X_25+X_26-X_12=0; Eq2y:=Y_12-Y_25-mu*X_26=0; Eq2m:=-mu*170*X_26+600*X_25-300*X_26=0; Eq3x:=X_34-X_36+X_13=0; Eq3y:=mu*X_36-Y_13=0; Eq3m:=-700*X_34-mu*170*X_36+300*X_36=0; Eq4x:=-X_34+X_45=0; Eq5x:=X_25-X_45=0; Eq5y:=Y_25-F=0; Eq5m:=100*X_45-400*F=0; vars:={X_16,Y_16,X_12,Y_12,X_13,Y_13,X_26,Y_26,X_36,X_34,X_25,Y_25,X_45}; eqs:={Eq1x,Eq1y,Eq1m,Eq2x,Eq2y,Eq2m,Eq3x,Eq3y,Eq3m,Eq4x,Eq5x,Eq5y,Eq5m}; soln:= simplify(solve(eqs,vars));assign(soln); F_1:=radsimp(sqrt(X_13^2+Y_13^2)); F_2:=radsimp(sqrt(X_12^2+Y_12^2)); F_3:=radsimp(abs(X_34)); F_4:=radsimp(sqrt(X_25^2+Y_25^2)); F_5:=radsimp(abs(X_45)); Max_force := evalf(max(abs(F_1),abs(F_2),abs(F_3),abs(F_4),abs(F_5)))*N; #printf(`**********************\n\n`); #printf(`FORCE ANALYSIS RESULTS \n\n`); #printf(`**********************\n`); #printf(`Force per bolt`); print(eval(Max_force)); RETURN(subs(N=1,eval(Max_force))): end: bolt_analysis:= proc(U,FS,MF) local units,Fact_safety,mu, Max_force,total_bolts, Strength, sig, Force_bolt, thread_area, area,Area, act_stress, Cost, total_cost, plot_opt, Choose_area, Choose_dia, Cost_fact,Cost_func,Cost_matl,clear_units,reset_units,Stress; global m,mm,N,bolt,dollars,MPa: plot_opt:= axes=frame, projection=.6: Choose_area:=area->piecewise(area<=5.03,5.03,area<=6.78,6.78,area<=8.78,8.78,area<=14.2,14.2,area<=20.1,20.1,area<=28.9,28.9,area<=36.6,36.6,area<=58.0,58.0,area<=84.3,84.3,area<=115,115,area<=157,157,area<192,192,245)*mm**2: Choose_dia:=area->piecewise(area<=5.03,3,area<=6.78,3.5,area<=8.78,4,area<=14.2,5,area<=20.1,6,area<=28.9,7,area<=36.6,8,area<=58.0,10,area<=84.3,12,area<=115,14,area<=157,16,area<192,18,20)*mm: Cost_fact:=area->piecewise(area<=5.03,.08,area<=6.78,.11,area<=8.78,.14,area<=14.2,.15,area<=20.1,.16,area<=28.9,.17,area<=36.6,.18,area<=58.0,.21,area<=84.3,.22,area<=115,.24,area<=157,.26,area<192,.28,.30)*dollars/bolt: Cost_func:=num->piecewise(num<=100,1.0,num<=500,.9,num<=1000,.75,num<2000,.66,.5)*bolt: Cost_matl:=sig->piecewise(sig<=200,1.0,sig<=350,1.2,sig<=520,1.5,sig<=700,1.7,2.0): clear_units := proc() global m,mm,N,bolt,dollars,MPa: m := 1: mm := 1: N := 1: bolt := 1: dollars := 1: MPa := 1: end: reset_units := proc() global m,mm,N,bolt,dollars,MPa: m := 'm': mm := 'mm': N := 'N': bolt := 'bolt': dollars := 'dollars': MPa := 'MPa': RETURN(NULL) end: Stress:=Strength[proof]=(Force_bolt*Fact_safety)/Area[thread]: total_bolts:=units*5; Strength[proof]:=320e6*N/m**2; sig:=Strength[proof]*m**2/(N*1e6): Force_bolt:=Max_force*N; units:=U; Fact_safety:=FS; Max_force:=MF; #printf(`*********************\n\n`); #printf(`COST ANALYSIS RESULTS \n\n`); #printf(`*********************\n`); thread_area :=solve(eval(Stress),Area[thread]); area:=subs(m=1000*mm,thread_area): Area[act_thread]:=Choose_area(subs(mm=1,area)); act_stress := rhs(subs(Area[thread]=Area[act_thread],Stress)): Cost:=Cost_func(total_bolts)*Cost_fact(subs(mm=1,area))*Cost_matl(sig)*total_bolts; #printf(`Area of thread:`); print(eval(Area[act_thread])); #printf(`Total cost for %d bolts:`,eval(units)); return(eval(Cost/dollars)); clear_units(): Force_bolt:='Force_bolt':Fact_safety:='Fact_safety':Area[thread]:=Area[act_thread]: #print(plot3d(rhs(Stress),Force_bolt=0..5000,Fact_safety=1..5,plot_opt, #labels=['Force_bolt','Fact_safety','Stress'],title=`Allowable Stress`, #orientation=[-68,81])); Area[thread]:='Area[thread]': total_cost:=Cost_fact(Area[thread])*Cost_func(total_bolts)*Cost_matl(sig)*total_bolts: Area[thread]:=solve(eval(Stress),Area[thread])*1e6: #print(plot3d(eval(total_cost),Force_bolt=0..10000,Fact_safety=1..5,plot_opt, #labels=['Force_bolt','Fact_safety','Cost'],title=`Total Cost`, #orientation=[-127,64])); Force_bolt:= Max_force: #plot(eval(total_cost),Fact_safety=1..5,labels=['Fact_safety','Cost'], #title=`Cost Vs Safety`); reset_units(): end: end module:
This indicates the end of the module declaration.
> libname:="c:/Paul/MyLib",libname;
This tells Maple where you want to create the library. (Simply substitute for your proper library Directory location).
> #march('create',libname[1],100);
Use the Maple "march" command (a sort of "Maple Archive") to create a library.
> savelib('brake');
Save the package into the library. Then test the package and implement in other worksheets (Maple, Microsoft XL2000, ...):
> with(brake);
> brake_analysis(3000,.1);
> bolt_analysis(200,2.6,brake_analysis(1000,.2));
Conclusion:
This worksheet clearly demonstrates the practicality and ease of creating a Maple package for encapsulating solutions.