Recall that the velocity and positions can be calculated usi
Solution
Let us create a function file with name computeVelocityandPosition.m
Inside this file, create the function that accepts all the 6 parameters as defined above and computes the velocity and position in the following way:
function [] = computeVelocityandPosition(a,t0,tf,n,x0,v0)
% Assuming that the value of n is given to compute the velocity and times at different values of tf ending with % 2sec
xt = zeros(20,1);
vt = zeros(20,1);
% computing the values of xt and vt for the range of t = [0.1,0.2,...2]
t = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.0,1.1,1.2,1.3,1.4,1.5,1.6,1.7,1.8,1.9,2.0];
for i = 1:n
% note that 0.1*i will represent the time at which we are calculating the xt and vt values
xt(i,1) = a*(0.1*i)+v0;
vt(i,1) = (1/2)*a*(0.1*20)^2+v0*(0.1*i)+x0
end
Use the subplot command to plot the curves
To call the function from the command window, simply write the name of the function with the 6 input parameters passed simultaeously while calling. Ensure that while calling the function the directory in which the file is saved is the same in which you are trying to make a call to the function.
Example: computeVelocityandPosition(-9.80655,0,2,20,1.3,0.1)

