Again I need some help writing them! 1. In this problem you are asked to develop
ID: 2995524 • Letter: A
Question
Again I need some help writing them!
1. In this problem you are asked to develop a matlab function that will calculate the velocity of a ball when it hits the ground, if the ball is dropped from a height "h" above the ground.
You should have the following function format:
[Velocity] = Ball_Drop(Height)
2.
recreate a function that takes any length vector x of values, eg:
x = [1 1.3 2 2.3 4]
and calculate the average value and product of these vector values. You may not use the built-in "average" or "product" functions in matlab.
The function should have the following input/output variables and should be saved as getAverageProduct.m:
[averageVal, product] = getAverageProduct(x)
Explanation / Answer
The matlab codes are
1. function velocity = Ball_Drop(height)
g = 9.8;
velocity = sqrt(2*g*height);
end
2.
function [averageVal,product] = getAverageProduct(x)
product = 1;
n = size(x,2);
averageVal = sum(x)/n;
for i=1:n
product = product*x(i);
end
end