MATLAB的问题,那位大侠能帮个忙,后天就要交作业了,非常感谢

来源:百度知道 编辑:UC知道 时间:2024/05/23 14:24:37
1. The Fibonacci numbers are computed according to the following relation:

with F0=F1=1.
(1) Write a function, F=fibo(n), to generate Fibonacci numbers in a vector F. Compute the first 10 Fibonacci numbers using the function;
(2) For the first 50 Fibonacci numbers, compute the ratio

It is claimed that this ratio approaches the value of the golden mean . What do your results show?

2. (Optional) Zeller's Congruence is a formula that calculates the day of the week given the date (within a limited range of years). The formula is:
day = 1 + ([2.6m - 0.2] + d + y + [y/4] + [c/4] - 2c) modulo 7
where the square brackets mean take the integer part, modulo 7 means the remainder when divided by 7, and
d = day of the month (e.g. 1 to 31)
m = month number with March=1, ..., December=10, January=11,
February=12. Assign

咋又来问了,我不是已经帮你做好了吗?
第1题 建立如下的m文件(知道怎么建m文件吗,file->new->m-file,然后把下面的东西敲进去,然后保存file->save,文件名就叫fibo.m)
function f=fibo(n)
if n==0
f=1;
else
if n==1
f=[1 1];
else
temp=fibo(n-1);
f=[temp,temp(end)+temp(end-1)];
end
end

下面是答案
第(1)小题
在命令行里敲
fibo(9)
屏幕就会显示
ans =

1 1 2 3 5 8 13 21 34 55
第(2)小题
在命令行里敲
a=fibo(50);
fibo(49)./a(2:end)
屏幕就会显示
ans =

Columns 1 through 9

1.0000 0.5000 0.6667 0.6000 0.6250 0.6154 0.6190 0.6176 0.6182

Columns 10 through 18

0.6180 0.6181 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180

Columns 19 through 27

0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180

Columns 28 through 36

0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180

Columns 37 through 45

0.6180 0.6180 0.6