help-octave
[Top][All Lists]

## Re: Fitting function

 From: Doug Stewart Subject: Re: Fitting function Date: Sat, 10 Aug 2019 07:45:15 -0400

On Fri, Aug 9, 2019 at 10:31 PM mrodrig <address@hidden> wrote:
Hello,
I am new with octave.

I have a data set (x,y) and I have a theoretical function that depend on the
x value. In other words, for example, for x < b, f=10*x*a and for x>=b,
f=-10*x*a. I need to perform the fitting of the theoretical function to the
experimental data and obtain the value of R parameter.

Here is my code example

x=[1,2,3,4,5,6,7,8,9,10];
y=[0,2,6,10,12,10,7,5,1,0];
R=2;
N=1;
plot(x,y)
hold
for r=min(x):1:max(x)
if x(N) < 5
y(N)=10*x(N)*R;
elseif x(N) >= 5
y(N)=-10*x(N)*R;
endif
N=N+1;
endfor

I used R=2 as a starting parameter

How can I do?

It is possible to use leasqr?

thanks very much

--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html

Your formula for the straight lines needs an y offset
I have a solution for you if you want it.
--
DAS