input and output functions

7 ビュー (過去 30 日間)
N/A
N/A 2020 年 11 月 24 日
コメント済み: N/A 2020 年 11 月 24 日
Please let me know how to fix my code so that mat lab will run.
Here is my work so far:
I created a file and saved it as Fibseq.m
for k=3:n
[f]=fibseq(n)
f(k)=f(k-1)+f(k-2)
%
end
I created a new live script and attempted to run it.
f(1)=1;
f(2)=2;
fibseq(20)
Here is the homework prompt:

採用された回答

Jan
Jan 2020 年 11 月 24 日
  1. Name your function fibseq. So call it fibseq.m, not "Fibseq.m". The case matters in Matlab.
  2. It will have one input n and one output f:
function f = fibseq(n)
3. Body :
f = zeros(1, n); % Pre-allocation
f(1) = 1;
f(2) = 2;
for k = 3:n
f(k) = f(k-1) + f(k-2);
end
end
Ready.
  2 件のコメント
N/A
N/A 2020 年 11 月 24 日
I did what you mentioned. MAT LAB asks to change the name fibseq to untitled, so I changed the name of the document to fibseq.mlx and now I cannot get MAT LAB to run no matter what I do. Please advise.
N/A
N/A 2020 年 11 月 24 日
It works now. Thank you.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGPU Computing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by