MATLAB Please Help For this assignment you will write one sc
MATLAB. Please Help!
For this assignment, you will write one script-m file and name it InClass6.m
You will also write 2 functions with the names of CylinderCalc and Ballistic
You will call all of your functions as described using the script-m file. Once all parts of the script file run without errors, publish your script-m file to a pdf file
Write a function named CylinderCalc to perform the necessary calculations outlined on the previous slide. Note that diameter and height can be vectors
Write a script-m file that calls your function CylinderCalc with the following inputs(do not suppress the outputs):
[vol, sa] = CylinderCalc(10,5) Diameter = [1 2 3 4 5 6]; Height = [2 4 6 8 10]; [vol2, sa2] = CylinderCalc(Diameter, Height)
Write a function called Ballistics. It has two inputs: initial velocity and launch angle. There is one output the range of the projectile. The range will be calculated from the initial velocity and the launch angle. Use a value of g=9.8 m/s2 for gravity. Function should handle scalar values and vector values for velocity and launch angle.
Formula to use is: range=(velocity^2/g)*sin(2*angle)
Note to handle vectors, proper matrix multiplication is needed. In this case use the transpose(put a ‘ at the end of the variable name) of velocity in the equation and .^ for the power calculation. With vectors for velocity and angle, range will be a two dimensional array.
In your script file add a new section for ballistics and call this function with the following values:
range = Ballistic(100,pi/4) % output this range value using fprintf with a descriptive phrase using the velocity and angle resulting in the range calculated
angle = 0:0.01*pi:pi/2; % vector of angle values
velocity = [50 100 150 200]; % velocity in meters/second
Range = Ballistic(velocity,angle); % range is a two dimensional array result
Plot(angle, range,’linewidth’, 2) % plot the results should be 4 plots on the same figure
Add a legend to the plot with titles of 50 m/s, 100 m/s, 150 m/s and 200 m/s
Add an x axis label of cannon angle(radians) and a y axis label of range(meters)
Add a title of Projectile Range
Use the MATLAB help command for information on topics you have forgotten
Solution
m script file named class6.m
************************************************************
Diameter = [1 2 3 4 5 6];
Height = [2 4 6 8 10];
[vol2, sa2] = CylinderCalc(Diameter, Height);
angle = 0:0.01*pi:pi/2; % vector of angle values
velocity = [50 100 150 200]; % velocity in meters/second
range = Ballistic(100,pi/4);
fprintf(\'velocity is %6.4f and angle is %6.4f\', velocity,angle );
plot(angle,range);
***********************************************************************
%%%%Function CylinderCalc
function [vol2,sa2]=CylinderCalc(Diameter,Height)
m=length(Diameter);
n=length(Height);
for i=(1:m)
for k=(1:n)
vol2(i,k)=pi*(Diameter(i))^2/4*Height(k);
sa2(i,k)=pi*Diameter(i)^2/2*Diameter(i)*Height(k);
end
end
end
********************************************************************************************************
%%%%%%Ballistic FUnction
function [range]= Ballistic(velocity,angle)
g=9.8;
range=(velocity\'.^2/g)*sin(2*angle);
end
******************************************************************************************************
