(1) 将上面计算Fibnacci的程序改成一个子程序,并编写一个主程序,结合上面的循环语句计算n从3到5情况下的值。
(2) 编写一个MATLAB函数,实现函数最大值和最小值的计算。
建议的函数输入值
first_value — The first value of x to search
last_value — The last value of x to search
num_steps — The number of steps to include in the search
func — The name of the function to search
建议的函数输出值
xmin — The value of x at the which minimum was found
min_value — The minimum value of f(x) found
xmax — The value of x at the which maximum was found
max_value — The maximum value of f(x) found
function [ y ] = fi( )
n=input('请输入n值');
a(1)=1;
a(2)=2;
k=3;
while k<=n
a(k)=a(k-1)+a(k-2);
k=k+1;
end;
fprintf('f( ');
fprintf('%d',n);
fprintf(')为');
disp(a(n));
end
function [ a ] =m( )
num=input('请输入需要计算数字的个数');
count=1;
while count <= num