フィルターのクリア

Average function of squares

2 ビュー (過去 30 日間)
Lewis HC
Lewis HC 2023 年 1 月 3 日
編集済み: Lewis HC 2023 年 1 月 20 日
Greetings everyone, I'm trying to create a function called proms that returns mm, which is the average of the squares of the first nn positive integers, where nn is a positive integer and is the only input argument. For example sum(). My code is this:
Thank you dear friends!
  2 件のコメント
John D'Errico
John D'Errico 2023 年 1 月 3 日
Don't post a picture of your code. Paste in the code itself. It is just text! Then someone else can paste that code into MATLAB to help you. While this is not a lot of code, it still slows down someone who might help you. Do you really want to make it even slightly more difficult to get help?
Lewis HC
Lewis HC 2023 年 1 月 3 日
Ok thank you dear friend
function mm=proms(nn)
nn=(x+1).^2
sum(nn)/n
end

サインインしてコメントする。

採用された回答

DGM
DGM 2023 年 1 月 3 日
編集済み: DGM 2023 年 1 月 3 日
Here's one basic way:
proms(5)
ans = 11
proms(11)
ans = 46
function mm = proms(nn)
% MM = PROMS(NN)
% calculate the mean square of the positive integers
% less than and equal to NN
mm = mean((1:nn).^2);
end
... or for further simplification, see this thread:
  1 件のコメント
Lewis HC
Lewis HC 2023 年 1 月 4 日
Thank you dear friend!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStartup and Shutdown についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by