EME 3214 - Matlab Curve Fitting / Regression Example

Поделиться
HTML-код
  • Опубликовано: 27 окт 2024

Комментарии • 42

  • @SleepinDevil
    @SleepinDevil 9 лет назад

    Looking at 5:22, are you sure you got that the right way round? It was my understanding that the order was the other way round. IE for your example the 1st number is the "x^2" coefficient, the 2nd number is the "x" coefficient and the 3rd number is the y-axis intercept.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      Sigmund Freud You are correct. P is a row vector of length N+1 containing the polynomial coefficients in descending powers, P(1)*X^N + P(2)*X^(N-1) +...+ P(N)*X + P(N+1). I will make a note on the video - thank you for catching that.

  • @cindydelgado7680
    @cindydelgado7680 9 лет назад

    Thanks a lot! It has been really helpful

  • @mrchiragjain92
    @mrchiragjain92 10 лет назад

    To create a linearly spaced vector use "linespace" function in matlab.

  • @nawfalalzubaidi9278
    @nawfalalzubaidi9278 10 лет назад

    That was very helpful :)

  • @MrsZqiizfiaesy
    @MrsZqiizfiaesy 9 лет назад

    Greetings Sir,
    Do you by any chance have the tutorial for r_squared that you explained in 13.06.
    I wanted to use the same technique.
    Thank you in advance.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      MrsZqiizfiaesy I don't have a tutorial, but the calculation is simple:
      function rsqd = r_squared(y_data, residuals)
      % return R^2 statistic for results of a regression
      % r_sqd = r_squared(y_data, residuals)
      %
      % where "y_data" is a vector with the dependent data in the regression and
      % "residuals" is a vector of the residual values (regressed minus actuals)
      mean_y = mean(y_data);
      sum_sqr_tot = sum((y_data-mean_y).^2);
      sum_sqr_err = sum(residuals.*residuals);
      rsqd = 1-(sum_sqr_err/sum_sqr_tot);

    • @MrsZqiizfiaesy
      @MrsZqiizfiaesy 9 лет назад

      GeoffreyThorpe123 Omg! you really help me with this Sir. :)
      y_data is the data that we obtained from the regression?
      Thank you so much sir.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      MrsZqiizfiaesy y_data would be the raw data, most likely from samples taken from our system. For example, y_data might be the temperature measured in a reactor (dependent variable) which we expect to vary as a function of flow rate and external heat applied (independent variables). A search on "statistics r squared" may help you with the statistical background.

    • @MrsZqiizfiaesy
      @MrsZqiizfiaesy 9 лет назад

      GeoffreyThorpe123 Oh now I understand. r squared are used to compare between the actual data and the curve fitting function. as the curve fitting function gets better, the r square would be approaching 1. Am I correct?
      Thank you so much sir. I really appreciate your help.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      MrsZqiizfiaesy
      correct

  • @yasminebibliophile9212
    @yasminebibliophile9212 8 лет назад

    i'm a begineer un programmation, i need help please
    we have a function for example: a+bsin(x)+ccos(x) ans we have solving the system ans find the values of unknown a,b ans c. i want the rest of programm that if we varie values of a,b ans c in different intervals we see the curve change and the squares change ( grow ans decrease)

    • @LightAndSportyGuy
      @LightAndSportyGuy  8 лет назад

      +Yasmine Bibliophile You are trying to fit a,b,c in the function data = a+b*sin(x)+c*cos(x) correct?
      Assuming you know the frequency and phase of x, you can simply create two new variables sx = sin(x) and cx = cos(x) and do a curve fit using the back slash operator and a created set of your new independent variables as I cover in the video.
      Otherwise, I would look into the fourier transform.

  • @jayantakumarmaji3018
    @jayantakumarmaji3018 10 лет назад

    really handy'

  • @brownsara87
    @brownsara87 8 лет назад

    Thank you so much for your helpful videos Mr , i have i question please , how can we fit a non linear curve using( cftool) by entering a (customer function) in it , ths function has this (arithmetic progression)form ( xn= fct(xn-1) ) knowing that we have the first value of x0 ,and thank you so much ,any note , remarque , help will be very helpful to me, have i nice day every body :)

  • @jigmetenzin7596
    @jigmetenzin7596 9 лет назад

    For example :
    X -value = Every 8-day ( 1Jan , 9Jan, 17Jan...)
    Y-value = ( Snow cover on corresponding date in sq.km2)
    I would like to fit a nonlinear regression curve in the data ( say power of the regression equation =6)
    After having fitted the curve on the sample points, I would like to extract every missing day information , e.g from 2jan to 8Jan, 10Jan-16Jan...from the curve).
    Can you upload some tutorial which may address my kind of problem.
    Thanking you.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      To begin with, you would need to convert your date values into simple numeric values using a function like datenum(...).
      This gives you the number of days since january 0,0000 so you want to subtract the large number that is the first date from all of the date numbers so you get numbers in a reasonable range (say from 0 to 100)
      Next, A = polyfit(datenumbers, snowdata,6) gives you the coefficents for a 6th order polynomial of the form snowdata = A0 + A1*datenumbers + A2*datenumbers^2 + ...
      To fill in your data, snowest = polyval(A,alldatenumbers); will do the job.
      You would want to convert the date numbers back to your date format with something like datestr(...).
      I would like to point out that using a high order regression on a data set with only a limited number of points can result in "over fitting" - you can get wiggles in the line you fit that are just a result of the noise in your data and not any actual physical phenomena.
      Make sure you plot the estimated values as a function of time to look for anomalies.
      Also, going even just a couple days beyond the range of dates that you had data for will give you results that are total garbage.

    • @jigmetenzin7596
      @jigmetenzin7596 9 лет назад

      GeoffreyThorpe123
      I have date format in Julian day. My data cover for all year with every 8-day data. Since I am very new to Matlab, I am not sure how to go about.
      Anyways, thanks for your valuable insight.

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      Jigme Tenzin
      the datenum function may or may not work for you. If not, you may have to write a script to parse your data and translate from text to numeric values. Check matlab central to see what might be available that other people have written for text translation.

  • @meriembouhbou6992
    @meriembouhbou6992 8 лет назад

    GeoffreyThorpe123 thank you so much for your explanation and useful video :) , i have a question please , how can we fit a curve that we have made from a function that we have creat with a program which contains loops ,please and thank you again Sir :)

    • @LightAndSportyGuy
      @LightAndSportyGuy  8 лет назад +1

      +meriem bouhbou I assume that you mean that the program had a loop as opposed to the data having a loop.
      If you can do the curve fitting after the loop has finished then it doesn't much matter how the data was created - you can use the methods from this video to fit a curve.
      If you want to update the curve fit at the same time as you are creating (or collecting) data points, you would either use the methods here over and over (which would require storing all the past values of the data) or you could use an algorithm like a weighted recursive least squares (or Potters Square Root algorithm to do the recursive least squares) which do not require you to maintain an array with, potentially, a large number of past data points. Potters Square Root is a little more numerically stable than the traditional recursive least squares algorithms.

  • @leonardcheri2118
    @leonardcheri2118 9 лет назад

    I hope I can get a quick answer from someone on this pattern recognition problem. I have an assignement due next week and have no idea how this is done, not to mentione my matlab skills are very casual.
    I have 2 classes and 300 elements. 150 elements will be used as a test and 150 elements in the training dataset that are classified. (Its a table/matrice with 75 values having 1 as first element in each row and 75 elements having a 2 in first element of each row). I need to use the closest neighbour classifier to estimate the error rate to find the best data combination that can be used as a training set. I have a small idea about how this method is used to classify but no idea how its used to find a combination of training data and if its something you do once or every time for each new element that need to be classified???? any help will be much apreciated

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      +Leonard Cheri Sorry, but this is not an area where I have much experience. You might find these helpful:
      www.mathworks.com/help/stats/supervised-learning-machine-learning-workflow-and-algorithms.html#bswluh9
      www.mathworks.com/help/stats/classification-nearest-neighbors.html
      In general, it appears to me that since you are trying to create a model that will separate different elements based on the known data, you would want to train your model on the set of combined response elements to get it to distinguish between the different responses as a function of your known data inputs. So, that would imply (If I am correct) that you would train your model using the first 150 data sets (75 for each element) and then you would use the model to predict the responses from the second set of 150 data sets and then you could compare the correct vs. incorrect predictions by comparing them with the known classification.
      Have you tried asking over on Matlab Central?

    • @leonardcheri2118
      @leonardcheri2118 9 лет назад

      +GeoffreyThorpe123 yes thats exaclty my plan. (I heard the word error when you said you are not going into that and though you might know) Im supposed to use 3 different classification methods but only after I figured out wich of the 150 training set are to be used to train because some might be not relevant or noise. I will try to figure out what that method is all about and will come back to you with concrete matlab implementations question if its ok for you :). It took me one day just to figure out how to separate the 300 elements into 2x150 using even and odd indexing :) I will try matlab sentral! thanks for your answer :)

    • @LightAndSportyGuy
      @LightAndSportyGuy  9 лет назад

      I will do my best to answer your questions.

    • @leonardcheri2118
      @leonardcheri2118 9 лет назад

      +GeoffreyThorpe123 ok I think I have a more concrete question :)
      I have to sets, training and test both are 150x5 (150 rows and 5 collums). The first collum is for classification. I have two classes 1 and 2.
      I need to run through every 150 elements(vector) of the test set and compare the distance from all elements of the training set and find the element with closest or smallest distance. then classify that test element as the closest element from the training is classified. I also need to go throught all combinations of collums or dimentions and find the best combination that classify best within each dimention. (like for dimention 1 I will be starting with collum 2 only then collum 3 then 4. And for dimension 2 I will start with collum 2 and 3, 2 and 4, 2 and5 and so on). Any help there is much apreciated :)

    • @leonardcheri2118
      @leonardcheri2118 9 лет назад

      +Leonard Cheri I need to calculate the error for every combination within each dimention and declare the combination with minimum error as the better to use for the next steps. Like in dimension 1, after testing every single collum, lets say collum 4 have the minimum error/ For dimention 2 => best combination will be collum 3 and 4 and so on) sorry this is getting pretty complicated (for me at least) Leo.o.Cheri@gmail.com if its easier for you to answer there :) and thanks in advance its all I can say :)