Please solve using MATLAB. Will rate! 4. Construction of user-defined functions
ID: 2073279 • Letter: P
Question
Please solve using MATLAB. Will rate!
4. Construction of user-defined functions (numerical solvers) Write an user-defined function FunTest1 with input variables A and k and output variable y The variable A is a two-dimensional data array (matrix). The function will first divide, element by element, the k-th row of A by the (k+2)-th row of A, then sum all the elements of the resulting vector and return be displayed if k+2 is larger than the number of rows of A this value to the output variable y. Note that an error message should Cut and paste the completed m-file below a) Benchmark testing is an important tool learned in BE 1500. Benchmark test your function on 1-onea120, 50 ) and k=13. The expqcted answer for the output is y-50. b) Apply your function to a 8x6 matrix a constructed by multiplying a column vector [1:8. to a row vector of [1: 61, and 5Explanation / Answer
clc;
clear all;
A=input('Enter two dimension array(matrix):');
k=input('Enter row number:');
FunTest1(A,k);
function y=FunTest1(A,k)
[m,n]=size(A);
if k+2>m
display('Enter proper row number');
else
m=A(k,:)./A(k+2,:);
y=sum(m);
display(y);
end
a)
Enter two dimension array(matrix):ones(20,50)
Enter row number:13
y = 50
b)
Enter two dimension array(matrix):[1:8].'*[1:6]
Enter row number:5
y = 4.2857