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 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
Steven Lord
2016 年 10 月 19 日
Show what you've done to try to solve this problem and ask a specific question about where you're stuck and you may receive some guidance.
回答 (2 件)
James Tursa
2016 年 10 月 21 日
編集済み: James Tursa
2016 年 10 月 21 日
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.
0 件のコメント
Soma Ardhanareeswaran
2016 年 10 月 21 日
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Install Products についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!