Write the Matlab code to evaluate the following sum E sigma
Write the Matlab code to evaluate the following sum: E = sigma^N_i = 1 (yi - ax_i)^2
Solution
% matlab code
x = input(\"Enter array x: \");
y = input(\"Enter array y: \");
a = input(\"Enter a: \");
l = length(y);
E = 0;
for i=1:l
E = E + (y(i)-a*x(i))^2;
end;
disp(\"E = \");
disp(E);
%{
output:
Enter array x: [1 2 3 4 5]
Enter array y: [4 5 6 1 2]
Enter a: 3
E =
301
%}
