Question

2. Writing Functions as m-files As mentioned above Functions can accept input arguments and return output arguments in the following format. function output argument = function name ( input arguments) The

function name must be the same as the name of the m-file./nMECH 1240 Lab 3 % cosgen.m % generates and plots a cosine wave % there is no output argument function cosgen(start, stop, points) % the function name is the same as the m-file t = linspace(start, stop, points); y = cos(t); plot(t,y) This Function may be used in a Script to generate a cosine wave. For example, % cosine.m % generates and plots a cosine wave start=input('Starting point? '); stop = input('End point ? '); points = input ('Number of points ? '); cosgen(start, stop, points);

Question image 1Question image 2