# Fitting function

5 messages
Open this post in threaded view
|

## Fitting function

 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
Open this post in threaded view
|

## Re: Fitting function

 On Fri, Aug 9, 2019 at 10:31 PM mrodrig <[hidden email]> 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 offsetI have a solution for you if you want it.-- DAS
Open this post in threaded view
|

## Re: Fitting function

 Dear Doug, Thanks very much for your replay. Please, could you send me the solution? -- Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html