用户函数

(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
  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值