USING MATLAB ONLY - PLEASE COMMENT CODE IN DETAIL Function regressConst : In thi
ID: 3940961 • Letter: U
Question
USING MATLAB ONLY - PLEASE COMMENT CODE IN DETAIL
Function regressConst:
In this function you will calculate a0 and a1 as defined above. The input to the function will be the two arrays define in getData and the output will be a0and a1. You must use for-loops to calculate the summations and may not use MATLAB built-in functions.
it may be advisable to calculate each of the four distinct individual summations separately and place the result in a variable and then use these variables to calculate a0 and a1.
Explanation / Answer
function [a0,a1] = getData(arr1,arr2)
%initializing values to zero first
a0 = 0
a1 = 0
%calculating summation of array1
for a = arr1
a0 = a0 + a;
end
%calculating summation of array2
for a = arr2
a1 = a1 + a;
end
end
%declaring arrays
arr1 = [1 2 3]
arr2 = [4 5 8]
[a0 a1] = getData(arr1,arr2)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.