I am realIy struggling in my MATLAB based engineering course
I am realIy struggling in my MATLAB based engineering course this semester and I need help writing a MATLAB code for a project in that class. I have to write a MATLAB code that analyzes the relationship between the angle and position of a slider crank mechanism. For my inputs I have the length of the mechanism arm and the angle of the arm from the fixed point. I also have to incorporate either linear or angular velocity into my input or else it will be too simple. The program must solve a problem that meets the following criteria: Need at least three functions, and two of them must be input-output functions, require user input(s) to run the program, generate plot(s), use at least one loop structure, use at least one selection structure (if statement or switch/case statement). Here is what I have so far.
Problem Statement To analyze the relationship between the angle and position of a slider crank mechanism. System Inputs and outputs Inputs: length of the mechanism arm and the angle of the arm from the fixed point. outputs: Displacement of the joints and the position of the arms relative to the horizontal axi User Inputs Distance between the crank and point C Governing Equations Sin(a-BC/AC Cos(a) AB/AC User Defined Functions A function using the angle of arms to calculate the position of point C Selection Structures A switch to find the angle or position using each other. Loop Structure Have a loop using multiple lengths. Ex. BC 10:50 Validation results Validation results are online. http://ocw.metu.edu.tr/pluginfile.php/3961/mod resource content htm. http://homepages.udayton.edu/-myszkadh mct313/dsgn.pdf Variables AB -Crank arm length A Fixed point C-linear position. AC distance between the crank and position a -angle between crank arm line ACSolution
%This m-script shows a simple simulation for the crank-slider mechanism for % the crank shaft-piston mechanism % l = rod length (distance between piston pin and crank pin) % r = crank radius (distance between crank pin and crank center, i.e. half stroke) % A = crank angle (from cylinder bore centerline at TDC) % x = piston pin position (upward from crank center along cylinder bore centerline) %The crank-slider mechanism scretch % P % o % o % o % o N % * % * % * % O % O [0,0] is the pivot of the crank shaft l=30; r=15; X=[0 0 0]; Y=[0 r r+l]; X_Piston=[-7 7 7 -7 -7]; Y_Piston=[l-5 l-5 l+5 l+5 l-5]; h = plot(X,Y,\'LineWidth\',4,\'XDataSource\',\'X\',\'YDataSource\',\'Y\'); axis([-1.1*r 1.1*r -1.5*r 1.5*r+l]); set(gca,\'DataAspectRatio\',[1 1 1]) grid on hold(\'all\') g = plot(X_Piston,Y_Piston,\'r\',\'LineWidth\',4,\'XDataSource\',\'X_Piston\',\'YDataSource\',\'Y_Piston\'); angle=0:0.01:2*pi; x_circle=r.*cos(angle); y_circle=r.*sin(angle); i = plot(x_circle,y_circle,\'LineWidth\',4) for A=0:0.08:4*pi x=r*cos(A)+sqrt(l^2-r^2*sin(A)^2); N=[r*sin(A) r*cos(A)]; P=[0 x]; X=[0 r*sin(A) 0]; Y=[0 r*cos(A) x]; Y_Piston=[x-5 x-5 x+5 x+5 x-5]; refreshdata(h,\'caller\') refreshdata(g,\'caller\') refreshdata(i,\'caller\') drawnow pause(.1) end
