1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Least square curve fit in MATLAB for Alpha power law MOSFET model

Discussion in 'General Electronics Chat' started by ANALA, Aug 25, 2017.

  1. ANALA

    ANALA New Member

    Joined:
    Aug 14, 2017
    Messages:
    18
    Likes:
    0
    For function like y = a*(x-b)^c, how can I use the least square curve fit feature to find out the coefficients a, b and c? But If i use the custom equation in cftool it reports " Complex value computed by model function, fitting cannot continue. Try using or tightening upper and lower bounds on coefficients".
     
  2. ci139

    ci139 Active Member

    Joined:
    Apr 12, 2012
    Messages:
    388
    Likes:
    34
    it's about your input data - that is 2D vectors having 2D errors - if the errors are "bad" your fitting function won't cover the guessing of input errors

    it might be possible to mod the algorithm to do that - which may need a recursive pass (trial error numerical approach) or solving very complicated analytical function - either way the task requires one to stay sharp on it e.g. you must ensure the right results are produced - e.g. the line that best fits your input points + MOSFET physics
     
    Last edited: Aug 26, 2017
  3. BobW

    BobW Active Member

    Joined:
    Apr 28, 2010
    Messages:
    501
    Likes:
    52
    Location:
    Canada
    I suggest that initially you modify the function to:
    y = a*abs(x-b)^c
    This will prevent the situation of trying to raise a negative value to a non-integer power. Once the fitting process comes up with approximate values for a, b and c, you can try removing the absolute value constraint.
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. ANALA

    ANALA New Member

    Joined:
    Aug 14, 2017
    Messages:
    18
    Likes:
    0

    I have attached my data and script..
    predicted = @(a,x) a(1)*((x-a(2)).^a(3));

    a0 = [?:?:?];
    [ahat,resnorm,residual,exitflag,output,lambda,jacobian] = lsqcurvefit(predicted,a0,x,y);
    May i know how to set the initial value of a0 inorder to obtain the fit and extract the co-efficients a1,a2,a3...?
     

    Attached Files:

  6. BobW

    BobW Active Member

    Joined:
    Apr 28, 2010
    Messages:
    501
    Likes:
    52
    Location:
    Canada
    I haven't used that matlab function, so I can't comment on your script. However, the fundamental problem is that your function is undefined at certain values of x. To help understand what I'm saying, try calculating the following:
    (-3)^2.5
    A negative number raised to a non-integer power has an undefined value. At least, it will not produce a real value. It will produce a complex value.

    Therefore you must add some constraints. You have to make sure that one or both of the following conditions is true:
    x-b>=0
    or
    c must be an integer

    If you go with the first constraint, and taking into account that your first data point is x=0, then the value of b must always be negative. On the other hand if the exponent c is restricted to integer values, then b can take on any value positive or negative.
     

Share This Page