Leas squares curve fit problem

In summary: If your problem is that you want to find the value of A, B, C and D for the equation shown, you need to rescale x and y first.
  • #1
pazmush
32
0
The main problem is that I have no idea what I am doing. But second to that I am attempting to fit a curve to some data using the equation

y = ((1/A(x-B)^(C+1))+D)^-1

if that makes sense

I need to get the values for A,B,C and D and so have been looking into lsqnonlin but I am having problems. I may also be making life hard for myself as I am also trying to incorporate it into a GUI. Here is an example of what I have been trying

this is my function

Code:
   function F = myfun(x,Vg,Gd)
        A = x(1);
        B = x(2);
        C = x(3);
        D = x(4);
        
        F = (((1/(A.*(x-B)^(C+1)))+D)^-1)-Gd;
    end

this is how I attempt to use lsqnonlin

Code:
 cla reset;
     Vg = A.data(:,1);
     Id = A.data(:,6);
     Vd = A.data(:,5);
     Gd = (Id./Vd);
     
    
    x=lsqnonlin(@myfun,[1*10^9 -1 1 3*10^5],[],[],[],Vg,Gd);
    %Gd_new = (((1/(x(1).*(x-x(2))^(x(3)+1)))+x(4))^-1);
    %semilogy(Vg,Gd,'o',Vg,Gd_new);

can anyone give me a hand in either starting again or making this work?

thanks
 
Physics news on Phys.org
  • #2
is this matlab?

I have a problem with the choice of variable names.

You know that array x() that you have chosen to pass 4 constants (A,B,C,D) in one shot into the function? How come that the scalar x, and I mean the only 'x' in the equation, has the same name? I think you have to decouple those two things, for starters.
 
  • #3
If your problem is that you have vectors x and y that contain your data, and you want to find A, B, C and D for the equation shown as a fit to that data, try the curve fitting toolbox. Run cftool, select x and y as your data set, then under fit select custom equation and you can enter the equation in the form you want, and it will calculate the coefficients.
 

Related to Leas squares curve fit problem

1. What is the least squares curve fit problem?

The least squares curve fit problem is a mathematical method used to find the best-fitting curve for a set of data points. It involves finding the curve that minimizes the sum of the squared distances between the data points and the curve.

2. How is the least squares curve fit problem used in scientific research?

The least squares curve fit problem is commonly used in various fields of science, such as physics, chemistry, biology, and economics. It is used to analyze and model data, make predictions, and test hypotheses.

3. What is the difference between linear and non-linear least squares curve fitting?

Linear least squares curve fitting involves finding the best-fitting straight line for a set of data points, while non-linear least squares curve fitting involves finding the best-fitting curve that is not a straight line.

4. How do you determine the quality of a least squares curve fit?

The quality of a least squares curve fit is determined by the value of the sum of squared errors (SSE), also known as the residual sum of squares (RSS). A lower SSE/RSS value indicates a better fit.

5. Are there any limitations to using least squares curve fitting?

While least squares curve fitting is a useful tool, it does have limitations. It assumes that the data points are independent and normally distributed, and that the residuals are unbiased and have constant variance. It may not be appropriate for all types of data sets, such as those with outliers or non-linear relationships.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
900
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
14
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
8K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
9
Views
4K
  • Programming and Computer Science
Replies
9
Views
2K
Back
Top