MatLab Harmonic sequence array (while)?

2 ビュー (過去 30 日間)
Shalene
Shalene 2014 年 11 月 9 日
回答済み: Image Analyst 2014 年 11 月 10 日
In mathematics, the harmonic series is the divergent infinite series:
Equation
Write a MATLAB function M-file, HarmArrayWhile , to
Input a positive integer, last Use a while loop to create & return as output an array x , that contains the harmonic sequence Preallocate the x array Do not allow input to be an array. Do not allow input to be a a non-positive integer
Example
if last = 5, then x would be [1, 1/2, 1/3, 1/4, 1/5]
>>HarmArrayWhile(5) ans = 1.0000 0.5000 0.3333 0.2500 0.200

回答 (1 件)

Image Analyst
Image Analyst 2014 年 11 月 10 日
Hint: Check out the inputdlg() and zeros() functions.

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by