Question #15. Write a function file that determines the following sum using a for loop:
y=i=1n(3-2i)2
Use n as input and test the function for n=100.
Question #15. Write a function file that determines the following sum using a for loop:
y=i=1n(3-2i)2
Use n as input and test the function for n=100.
SOLUTION -
15 )
CODE -
function y = perform(n)
y = 0;
% looping from 1 to n
for i = 1:n
% adding each term to y
y += (3 - 2*i)^2;
end
end
% sample run
y = perform(100)
SCREENSHOT-
OUTPUT
IF YOU HAVE ANY DOUBT PLEASE COMMENT DOWN BELOW I
WILL SOLVE IT FOR YOU:)
----------------PLEASE RATE THE ANSWER-----------THANK
YOU!!!!!!!!----------
Get Answers For Free
Most questions answered within 1 hours.