Write a function called mysum that sums the first n positive numbers. Give the result x1 for n=20,and the result x2 for n=100.
Matlab code
Always save function file using function name
Here given code is save by mysum.m
code of function
function sum = mysum(n)
if(n>0)
sum=0;
for i=1:n
sum=sum+i;
end
else
disp('not
defined')
end
end
Result
Get Answers For Free
Most questions answered within 1 hours.