调用拟合好的函数

Matlab 2016要调用一个拟合好的函数非常简单:

f = fittype('a*x^2+b*exp(n*x)')  %给出函数
f =
     General model:
       f(a,b,n,x) = a*x^2+b*exp(n*x)
c = cfit(f,1,10.3,-1e2)         %给出相应参数,返回函数值
c =
     General model:
       c(x) = a*x^2+b*exp(n*x)
     Coefficients:
       a =           1
       b =        10.3
       n =        -100

但Matlab 2012稍微麻烦一些,要先定义句柄,然后再用feval调用句柄函数,才能获得函数值:

fhandle=@myfun;  % myfun 为外部函数
C=feval(fhandle, 1,10.3,-1e2)

Leave a Reply

Your email address will not be published. Required fields are marked *