In MATLAB Write a function that takes in a number n as an in
In MATLAB, Write a function that takes in a number, n, as an input and has one output, an array of length n that alternates 1’s and 0’s. If the length of the array is odd, start the array with a 1. If the length of the array is even, start the array with 0. Please use a loop to accomplish this.
2. Collaboration] Loops are very useful for doing the samecacuation over and over, very quickly Let\'s assume that we are building a bridge and need to determine the grade of steel we need for each fastener. Assume that we have another set of programs that returnms the tensile and shear forces that each joint will experience. We need to use the program we have already written to determinc which kind of fastener to use cn massc. As we want to store the data about fastcner type in an array of numbers, please use the following values for each grade of steel Steel Grade String Grade 1 Low Curbon Steel Grade 2 Low Carbon Steel Grade 5 Medium Carbon Steel e 82 Low Carbon Boron S Number Code Write program that takes in two arrays, the first with shear forces, the second array of the same length with tensile forces, for fastened joints. As an output, this function returns the type of metal to use in ths You can assume that no shear Forces are above 120000 and that no tensile forces are above 150000. Please call your tunction from Recitation 3 problem 1 to solve this. For example, ilf ShearForces = [10000, 100000,500001 And TensileForces-[25000. 120000.750001 Then GradesaalllRe:itation5Problm2ShearFares,TensileForces) Will retun the array: Grades =1, 8.2, 51 4x ·ana2010Solution
% matlab code to create alternate 1,0 array on basis of input n
function array = alternate(n)
if mod(n,2) == 0
array(1) = 0;
else
array(1) = 1;
end
for i=2:n
if array(i-1) == 0
array(i) = 1;
else
array(i) = 0;
end
end
end
n = input(\"Enter n: \");
result = alternate(n);
disp(result);
