|
MainProgram.m
--------------------------------
Coeff_init = [1 1];
global data
data.F = ... % give your data
data.k = [1:1:10];
Coeff = lsqnonlin('myoptifunction',Coeff_init);
--------------------------------
myoptifunction.m
---------------------------------
function rest = myoptifunction(Coeff)
global data
rest = data.F - 2 + 2*k-exp(data.k*Coeff(1))-exp(data.k*Coeff(2)) ;
------------------------------------
I hope it helps ...
"Pat Finder" <pfinder.nospam@netacc.net> a écrit dans le message de news:
fttfa6$hgr$1@fred.mathworks.com...
> [Using student version 7.1.0.124 (R14) SP3]
>
> I am trying to teach myself how to use lsqnonlin. This is
> for Nonlinear Least Squares (NLLSQ) regression.
>
> I am confused by the documentation. lsqnonlin is used to
> fit a non-linear function to given data.
>
> In my case, I'm trying to fit a Gaussian, which is a
> function of the mean and the variance -- two parameters.
>
> The documentation says to write your own function which
> takes in the parameters you are trying to estimate:
>
> "function F = myfun(x)
> k= 1:10;
> F = 2 + 2*k-exp(k*x(1))-exp(k*x(2));"
>
> In my case, the vector x would be the values of the mean and
> the variance. BUT -- how do I get the data points I'm
> trying to fit to in? Do I have to hard-code them into
> myfunc(x)?
>
> I don't want to have to write my own function for every data
> set I get...
>
> - Pat
>
|