MATLAB的问题,那位大侠能帮个忙,后天就要交作业了,1.The Fibonacci numbers are puted 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
网友回答
咋又来问了,我不是已经帮你做好了吗?
第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.6180 0.6180 0.6180 0.6180 0.6180 0.6180 0.6180 Columns 46 through 50 0.6180 0.6180 0.6180 0.6180 0.6180 下面你就在作业本上写We can find the ratio approaches the value of the golden mean.第2题建立如下m文件function day=dayofweek(x) d=x(1);m=mod(x(2)-2,12); yy=x(3)