Questions: A device constructed to throw various objects can impart up to 500 joules of kinetic energy to the object being thrown. For a given mass, can throw the object. This is represented in the diagram given below, and it fits a power law model. Velocities above the line cannot be a line can. Write a MATLAB program that will accept a value of mass [kg] and desired velocity [m/s] from the user and classify them as "Possible" of labeled on the diagram. You must use polyfit to determine the equation of the line, and then use these values to do the classification. (i) Click the icon to view the diagram for mass and velocity. ``` clear dlc Mass = input ('Enter the mass of the object [kg]: ') % ask for the mass of the object Vel = input ('Enter the velocity of the object [m/s]: ') % ask for the velocity of the object MData =[520 40]; VData=[10 5 3.54]; Params = polyfit( log10(MData),log10(VData),1 ); m=Params(1); b=10^Params(2); VBound = b* Mass^m ; % the velocity corresponding to Mass if Vel <= VBound Class = 'possible'; else Class = 'not possible'; end % print the result ('It is %s to throw a %0.1f kg object at a velocity of %0.1f m/s.', Class, Mass, Vel); ```

A device constructed to throw various objects can impart up to 500 joules of kinetic energy to the object being thrown. For a given mass, can throw the object. This is represented in the diagram given below, and it fits a power law model. Velocities above the line cannot be a line can.

Write a MATLAB program that will accept a value of mass [kg] and desired velocity [m/s] from the user and classify them as "Possible" of labeled on the diagram. You must use polyfit to determine the equation of the line, and then use these values to do the classification.
(i) Click the icon to view the diagram for mass and velocity.
```
clear
dlc
Mass = input ('Enter the mass of the object [kg]: ') % ask for the mass of the object
Vel = input ('Enter the velocity of the object [m/s]: ') % ask for the velocity of the object
MData =[520 40];
VData=[10 5 3.54];
Params = polyfit( log10(MData),log10(VData),1 );
m=Params(1);
b=10^Params(2);
VBound = b* Mass^m ; % the velocity corresponding to Mass
if Vel <= VBound
Class = 'possible';
else
Class = 'not possible';
end
% print the result
('It is %s to throw a %0.1f kg object at a velocity of %0.1f m/s.', Class, Mass, Vel);
```
Transcript text: A device constructed to throw various objects can impart up to 500 joules of kinetic energy to the object being thrown. For a given mass, can throw the object. This is represented in the diagram given below, and it fits a power law model. Velocities above the line cannot be a line can. Write a MATLAB program that will accept a value of mass [kg] and desired velocity [ $\mathrm{m} / \mathrm{s}$ ] from the user and classify them as "Possible" of labeled on the diagram. You must use polyfit to determine the equation of the line, and then use these values to do the classification. (i) Click the icon to view the diagram for mass and velocity. ``` 1 clear 2- dlc 3- Mass = input ('Enter the mass of the object [kg]: ') % ask for the mass of the object 4- Vel = input ('Enter the velocity of the object [m/s]: ') % ask for the velocity of the object 5-MData =[520 40]; 6- VData=[\begin{array}{lll}{10}&{5}&{3.54}\end{array}]; 7- Params = polyfit( log10(MData),log10(VData),1 ); 8- m=Params(1); 9- b=10^Params(2); 10 - VBound = b* Mass^m ; % the velocity corresponding to Mass 11 - if Vel < = VBound 12 - Class = 'possible'; 13 - else 14 - Class = 'not possible'; 15 - end 16 % print the result 17 - $\square$ ('It is $\% \mathrm{~s}$ to throw a $\% 0.1 \mathrm{f} \mathrm{kg}$ object at a velocity of $\% 0.1 \mathrm{fm} / \mathrm{s} . \mathrm{ln}$ ', Class, Mass, Vel); ```
failed

Solution

failed
failed

Solution Steps

Step 1: Get the mass and velocity inputs from the user

The code prompts the user to enter the mass and velocity using the input function. These values are stored in the variables Mass and Vel, respectively.

Step 2: Define the data points for the power law model

The code defines the x-coordinates (mass) and y-coordinates (velocity) of the points on the line using MData and VData. Note that the velocity corresponding to the mass of 5 kg has been corrected to 10 m/s.

Step 3: Fit the power law model using polyfit

The polyfit function is used to fit a first-degree polynomial (a line) to the log10 of the data. This is because a power law relationship _y = b_x^m becomes linear when taking the log of both sides: log(y) = log(b) + m*log(x). The output Params contains the coefficients of the fitted polynomial, which correspond to m (slope) and log(b) (intercept).

Step 4: Calculate the model parameters

The code extracts the slope m and calculates the coefficient b by taking 10 to the power of the intercept term (Params(2)). This reverses the log operation performed earlier, giving the actual value of 'b' in the power law equation.

Step 5: Calculate the velocity bound

The velocity bound (VBound) is calculated using the fitted power-law model. This represents the maximum velocity allowed for the given mass according to the power law relationship.

Step 6: Classify the possibility of throwing

The code compares the input velocity (Vel) with the calculated VBound. If the input velocity is less than or equal to the velocity bound, the throw is classified as 'possible'. Otherwise, it's classified as 'not possible'.

Step 7: Print the result

Finally, the code displays the classification result ('possible' or 'not possible') along with the input mass and velocity, formatted to one decimal place.

Final Answer:

clear
clc
Mass = input('Enter the mass of the object [kg]: ');
Vel = input('Enter the velocity of the object [m/s]: ');
MData = [5 20 40];
VData = [10 5 3.54];
Params = polyfit(log10(MData), log10(VData), 1);
m = Params(1);
b = 10^Params(2);
VBound = b * Mass^m;
if Vel <= VBound
    Class = 'possible';
else
    Class = 'not possible';
end
fprintf('It is %s to throw a %0.1f kg object at a velocity of %0.1f m/s.\\n', Class, Mass, Vel);

Was this solution helpful?
failed
Unhelpful
failed
Helpful