Question
Can you please program in MatLab #M6--------- clear clc M=[240,120,360];%all th masses Vi=[30,15,-45]%all the vel0cities before they collieded %---------------------------------------------------------------------- %i will be making 2 carts
Can you please program in MatLab
#M6---------
clear
clc
M=[240,120,360];%all th masses
Vi=[30,15,-45]%all the vel0cities before they collieded
%---------------------------------------------------------------------- %i will be making 2 carts colide by trail an error %I will be checking if momentum and kinetic energy is perserved %this will prove that the bodies collided %-----------Collison a bettween cart 2 and cart3 ------------------ Va=Vi;% Va values of vi that preserve the unchanged values
Va(2)=FinalVelocity(M(2),M(3),Vi(2),Vi(3));
Va(3)=FinalVelocity(M(3),M(2),Vi(3),Vi(2))
[CheckPa, CheckKEa] = check_p_KE_total(M,Va,M,Vi) %-----------Collison b bettween cart 1 and cart2 --------------------- Vb=Va;% Vb values of va that preserve the unchanged values
Vb(1)=FinalVelocity(M(1),M(2),Va(1),Va(2));
Vb(2)=FinalVelocity(M(2),M(1),Va(2),Va(1))
[checkPb,CheckKEb]=check_p_KE_total(M,Vb,M,Vi) %----------Collison c bettween cart 2 and 3 ------------------------------ Vc=Vb; % Va values of vb that preserve the unchanged values
Vc(2)=FinalVelocity(M(2),M(3),Vb(2),Vb(3));
Vc(3)=FinalVelocity(M(3),M(2),Vb(3),Vb(2))
[checkPc,CheckKEc]=check_p_KE_total(M,Vc,M,Vi) %----------Collison d bettween cart 1and2 ----------------------------- Vd=Vc; % Vd values of vc that preserve the unchanged values
Vd(1)=FinalVelocity(M(1),M(2),Vc(1),Vc(2));
Vd(2)=FinalVelocity(M(2),M(1),Vc(2),Vc(1))
[checkPd,CheckKEd]=check_p_KE_total(M,Vd,M,Vi)
%-------------expelantation---------------------------------------------- %Ans-there is 4 collisions becuase the final velocities of the carts fourth %collison makes it impossible for another collstion.cart 1 and 3 are going %in a oppisite direction and not faceing each other. cart1 and2 are going %in the same direction but cart1 is ahead of cart2and going faster. %cartcart 2 and 3 are moving in opposit drirctions and not faceing each %other. %Ans-- the change of momentum and Kinetic energey is 0
function Vf =FinalVelocity(M1,M2,V1,V2); DelM=M1-M2; SumM=M1+M2; Vf=(DelM/SumM)*V1+(2*M2/SumM)*V2; end
function [pT,KET]=p_KE_total(m,v) pT = sum(m.*v); %total mom KET=sum(1/2*m.*v.^2) %total K energy end
function[checkp, checkKE] = check_p_KE_total(m,v,m0,v0) [pT, KET] = p_KE_total(m, v); [pT0, KET0] = p_KE_total(m0,v0); checkp = pT-pT0; checkKE = KET - KET0; end
Starting with Exercise M6, make the script more useful by allowing someone to enter any array of three cart masses and any array of three initial velocities. (This can be done with two input statements, but you will need to inform the user exactly how to enter the values properly.) ADDITIONAL DESIGN SPECIFICATIONS 5. Use a WHILE loop. Include checks of total momentum and energy, but output something only when a check does not work out as expected. Use functions to make the script more efficient. 6. 7. 8. 9. Output the number of collisions and the final velocities of the three carts. Plan for contingencies. For instance, if there is ambiguity about which collision occurs first, you will need to ask for additional input from the user to find out which occurs first. The prompts for the inputs should be meaningful and appropriate. For instance, make sure people know that velocities "to the left" are entered as negative values. Also, make sure that people know that the "first" cart is on the left, the "second" is in the middle, and the third" is on the right. 10. The WHILE loop is like the FOR loop, except it keeps cycling until a certain criterion is no longer met. In this case, it is recommended to define a parameter that indicates whether or not there is another collision, then test it in the WHILE statement to decide whether or not you are done. It is also recommended to create a single function to determine: (1) whether or not there is another collision, and (2) which two carts collide nextStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started