help-octave
[Top][All Lists]

## Re: leasqr with bounds

 From: Przemek Klosowski Subject: Re: leasqr with bounds Date: Fri, 26 Jan 2018 10:31:24 -0500 User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2

```On 01/25/2018 10:09 PM, mrodrig wrote:
```
```In order to test the operation of the leasqr function I tried with the
following

x=[1:10]
y= [10,8,5.5,3.5,0,1.2,2.5,4.6,7.5,9.8]
F=@(x, p) (p (1) * x .^ 2 + p (2) * x + p (3))
a=1
b=1
c=1
p = [a,b,c];

wt=ones(size(x));
iter=400;
tol=0.000000001;
dFdp="dfdp";
dp=0.001*ones(size(p));
[f, pfit, kvg, iter, corp, covp, stdresid, Z, r2] = leasqr (Temp_bkg,
Int_Prom_bkg, par, F,tol, iter,wt, dp, dFdp);

and gives this results;
```
I did a lot of data fitting and so I'd like to help you on this. Thank you for providing the sample code you are working with---it makes it easy to engage. I think you mean to use x,y instead of what I assume are your original fitting data tables Temp_bkg and Int_Prom_bkg:
```
```
[f, pfit, kvg, iter, corp, covp, stdresid, Z, r2] = leasqr (x,y, par, F,tol, iter,wt, dp, dFdp)
```
```
because this gives the results you quote. Next, it seems, you need to do something like
```
options.bounds=[-5,5; -5,5; -1,1]
par=[1,1,1] # avoid exceeding the bounds in initial parameters
```
[f, pfit, kvg, iter, corp, covp, stdresid, Z, r2] = leasqr (x,y, par, F,tol, iter,wt, dp, dFdp, options)
```
and indeed we get no convergence.

```
I think that's because your function, with the parameter bounds you propose, will not fit the data. I concluded that by plotting your function with some values of parameters in your proposed range:
```plot(x,y,'o',x,F(x,[3,-15,1]))

```
Perhaps I missed something, but I ran out of time I could spend on it because I had to start by figuring out the small problems with running the code from the problem as you posed it: that's why it's important to cross-check and test the code you are about to publish, so that others don't have to.
```
```
I think that you need to play with the function F and the parameter limits by plotting and inspecting it, to find the reasonable values of initial parameters, in the way I showed above. Good luck and please come back with more questions as you gain experience with this problem.
```
Greetings

p

```