How can i implement following sum notation ?

I tried to write the code but it is wrong. How can i fix it? Thanks.

回答 (2 件)

Bruno Luong
Bruno Luong 2022 年 4 月 16 日

1 投票

call (without y=...)
soru(2,4)
Your function is not supposed to return any output

2 件のコメント

cagri sarac
cagri sarac 2022 年 4 月 17 日
it does not work
Bruno Luong
Bruno Luong 2022 年 4 月 17 日
編集済み: Bruno Luong 2022 年 4 月 17 日
"it does not work"
Your function still have problem it doesn't compute what you expect (I'm not here to do entirely the homework for you) but it certainly not longer throw an error:
function soru(x,n)
sum = 0;
k = 1;
prompt1="enter x ";
prompt2="enter n ";
x=input(prompt1);
n=input(prompt2);
for loop=k:n
sum=((3/x)^k)+sum;
end
disp(sum)
end
Result runing on my PC
>> soru(2,4)
enter x 1
enter n 10
30
>>

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

Matt J
Matt J 2022 年 4 月 16 日
編集済み: Matt J 2022 年 4 月 16 日

0 投票

function y=soru(x,n)
y=sum( (3./x).^(1:n) );
end

カテゴリ

ヘルプ センター および File ExchangeGet Started with MATLAB についてさらに検索

製品

リリース

R2020a

タグ

質問済み:

2022 年 4 月 16 日

編集済み:

2022 年 4 月 17 日

Community Treasure Hunt

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

Start Hunting!

Translated by