1. Engineering
  2. Computer Science
  3. can you please program in matlab m6 clear clc m240120360all...

Question: can you please program in matlab m6 clear clc m240120360all...

Question details

Can you please program in MatLab

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 next.




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



[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



%----------Collison c bettween cart 2 and 3 ------------------------------
Vc=Vb; % Va values of vb that preserve the unchanged values



%----------Collison d bettween cart 1and2 -----------------------------
Vd=Vc; % Vd values of vc that preserve the unchanged values




%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
%Ans-- the change of momentum and Kinetic energey is 0

function Vf =FinalVelocity(M1,M2,V1,V2);

function [pT,KET]=p_KE_total(m,v)
pT = sum(m.*v); %total mom
KET=sum(1/2*m.*v.^2) %total K energy

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;

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution