function [ v_final ] = inelastic( m1, v1, m2, v2 ) %INELASTIC A function to calculate the final velocity of two %objects that stick together after they collide. %TUTORIAL PROGRAM#1 -- Created by R.Sonnenfeld, New Mexico Tech Physics %Version 1.0 9/5/2005 % %Inputs: % m1, m2 are scalars which are mass of two objects in kg % v1, v2 are Matlab vectors (but not traditional physics vectors) % such that (v1(1)) is the magnitude of the velocity and % (v1(2)) is the angle the velocity makes with the x-axis % v2 applies to the second object. % %Outputs: % v_final is a two-component MATLAB vector such that % v_final(1) is the magnitude of the velocity and % v_final(2) is the angle the velocity makes with the x-axis % %Examples of Usage and results: %>> inelastic(2,[1; 45],2,[1 ;45+180]) %ans = % 0.0000 % 180.0000 % %>> inelastic(2,[1; 45],2,[1 ;-45]) %v1_vec= % 0.7071 % 0.7071 %v2_vec= % 0.7071 % -0.7071 %Momentum1= % 1.4142 % 1.4142 %Momentum2= % 1.4142 % -1.4142 %v_final_vec = % 0.7071 % 0 %ans = % % 0.7071 % 0 % Initialize v_1mag=v1(1); v_1angle=v1(2); v_2mag=v2(1); v_2angle=v2(2); %Convert angles to radians v_1angle=v_1angle*pi/180; v_2angle=v_2angle*pi/180; %Calculate x,y components from magnitude and theta v_1x=v_1mag*cos(v_1angle); %Calculate components v_1y=v_1mag*sin(v_1angle); v_2x=v_2mag*cos(v_2angle); v_2y=v_2mag*sin(v_2angle); %Create Matlab vectors containing x and y components of velocity v1_vec=[v_1x;v_1y]; v2_vec=[v_2x;v_2y]; disp('v1 in component form: v1_vec=');disp(v1_vec); disp('v2 in component form: v2_vec=');disp(v2_vec); %Calculate momentum vectors in x, y component form p1_vec=m1*v1_vec; p2_vec=m2*v2_vec; disp('Momentum1 in component form: p1_vec=');disp(p1_vec); disp('Momentum2 " " " " " p2_vec=');disp(p2_vec); %Calculate total final momentum and velocity (in vector form) ptot_vec=p1_vec+p2_vec; v_final_vec=ptot_vec/(m1+m2) % %Convert final velocity from component form back to magnitude and angle %form v_final_mag=sqrt(v_final_vec'*v_final_vec); v_final_angle=atan2(v_final_vec(2),v_final_vec(1)); %Convert final angle back to degrees v_final_angle=180*v_final_angle/pi; %Make a matlab vector out of the final magnitude and velocity v_final=[v_final_mag;v_final_angle];