# Write a function that takes an input argument n, checks whether or not n is positive, and then provides the sum: 1 + √2/2! + √3/3! + ⋯ + √n/n!.

1 view (last 30 days)
Malik McMillon on 19 Oct 2016
Edited: James Tursa on 21 Oct 2016
Write a function that takes an input argument n, checks whether or not n is positive, and then provides the sum: 1 + √2/2! + √3/3! + ⋯ + √n/n!.
##### 2 CommentsShowHide 1 older comment
Malik McMillon on 19 Oct 2016
I do not know where to start

James Tursa on 21 Oct 2016
Edited: James Tursa on 21 Oct 2016
1) Create a function file called myfunction.m in your working directory. E.g.,
edit myfunction.m
2) Put the following code into this file:
function result = myfunction(n)
% Insert your n check code here
result = 0; % initialize the result
% Insert a loop here to add the terms to result
return
end
Insert your code for n checking and term adding into the places indicated. Also add comments to this file to state the purpose of the function, show the calling syntax, and explain what the inputs and outputs are.

Soma Ardhanareeswaran on 21 Oct 2016
The 'while' statement example in the following link is a good starting point - https://www.mathworks.com/help/matlab/matlab_prog/loop-control-statements.html