MATLAB Help - Quadratic Splines

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

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

  • @harshdhiman3236
    @harshdhiman3236 4 года назад +1

    Who else felt extremely satisfied when he plotted the quadratic spline in the end?
    Thanks so much for this. This was incredibly helpful.

  • @lenewang843
    @lenewang843 4 года назад +1

    Thanks for the detailed explainations! Very helpful! Head to cubic splines now!

  • @v54474
    @v54474 6 лет назад +1

    Great video. Would you please share your codes for quadratic spline?

    • @CarlosMontalvo251
      @CarlosMontalvo251  6 лет назад +5

      clear
      clc
      close all
      X = (-10:10)';
      Y = sin(5*X);% + rand(length(X),1);
      fig = figure();
      set(fig,'color','white')
      set(gca,'FontSize',18)
      p0 = plot(X,Y,'b*','MarkerSize',10);
      xlabel('X')
      ylabel('Y')
      grid on
      hold on
      %%%Linear Splines
      for idx = 1:length(X)-1
      m = (Y(idx+1)-Y(idx) )/(X(idx+1)-X(idx));
      xspline = linspace(X(idx),X(idx+1),10);
      yspline = m*(xspline-X(idx)) + Y(idx);
      p1 = plot(xspline,yspline,'g-','LineWidth',2);
      end
      %%%Quadratic Splines
      N = length(X);
      n = N-1;
      %%%%Create H0 = [2*(n-1) x 3*n]
      H0 = zeros(2*n-2,3*n);
      K0 = zeros(2*n-2,1);
      for idx = 1:(n-1)
      col = idx;
      row = 2*(idx-1)+1;
      H0(row,col) = X(idx+1)^2;
      H0(row+1,col+1) = X(idx+1)^2;
      H0(row,n+col) = X(idx+1);
      H0(row+1,n+col+1) = X(idx+1);
      H0(row,2*n+col) = 1;
      H0(row+1,2*n+col+1) = 1;
      K0(row) = Y(idx+1);
      K0(row+1) = Y(idx+1);
      end
      %%%Create H1 = [n-1 x 3*n];
      H1 = zeros(n-1,3*n);
      for idx = 1:n-1
      H1(idx,idx) = 2*X(idx+1);
      H1(idx,idx+1) = -2*X(idx+1);
      H1(idx,n+idx) = 1;
      H1(idx,n+idx+1) = -1;
      end
      %%%Create HE
      HE = zeros(2,3*n);
      HE(1,1) = X(1)^2;
      HE(1,n+1) = X(1);
      HE(1,2*n+1) = 1;
      HE(2,n) = X(end)^2;
      HE(2,2*n) = X(end);
      HE(2,end) = 1;
      %%%Compute H
      H = [H0;H1;HE];
      [r,c] = size(H);
      %%%Compute K
      K = zeros(r,1);
      K(1:(2*(n-1))) = K0;
      K(end-1) = Y(1);
      K(end) = Y(end);
      %%%Assume now that a1 = 0
      H = H(:,2:end);
      coeffs = inv(H)*K
      %%%Get all your A's,B's, and C's
      A = [0;coeffs(1:n-1)]
      B = coeffs(n:2*n-1)
      C = coeffs(2*n:end)
      %%%%Plot the results
      for idx = 1:n
      xspline = linspace(X(idx),X(idx+1),10);
      yspline = A(idx)*xspline.^2 + B(idx)*xspline + C(idx);
      p2 = plot(xspline,yspline,'r-','LineWidth',2);
      end
      legend([p0 p1 p2],'Measured Data','Linear Spline','Quadratic Spline')

    • @ysabellebiancaviray1642
      @ysabellebiancaviray1642 3 года назад

      Monte Carlos nice

  • @user-ny6wn3lg4x
    @user-ny6wn3lg4x Месяц назад

    write a MATLAB strip to solve the polynomial
    p(x)=2x^5-3x^4+7x^3-x^2+5x-6=0
    Can you please help me with this?

  • @luvnaangel
    @luvnaangel 6 лет назад

    plz can you do for a cubic spline using large yields data for estimating yields curve.I am having many difficulties in estimating yield curve.Would be grateful to you.Thank you

    • @cjcar178
      @cjcar178 6 лет назад

      It's on my to-do list. Cubic splines are just very complex so I haven't gotten around to it. I will try and upload it this weekend if I have time.

    • @CarlosMontalvo251
      @CarlosMontalvo251  6 лет назад +1

      @@cjcar178 ruclips.net/video/gfSKOfHRooQ/видео.html

  • @deehanchowdhury1230
    @deehanchowdhury1230 6 лет назад

    I need a help regarding how to import csv data without empty cells....please make a video on that cause only reading csv data is explained in thousand ways over net but how to deal with the blank cells in csv file isn't explained anywhere...at least i didn't find it.

    • @CarlosMontalvo251
      @CarlosMontalvo251  6 лет назад

      Can you copy and paste an example csv file?

    • @CarlosMontalvo251
      @CarlosMontalvo251  6 лет назад

      Have you tried this? ruclips.net/video/_Lnnw9WLntE/видео.html

    • @CarlosMontalvo251
      @CarlosMontalvo251  6 лет назад

      or this? ruclips.net/video/L-pBWbNWJtY/видео.html

    • @deehanchowdhury1230
      @deehanchowdhury1230 6 лет назад

      www.sharecsv.com/s/e850a3da764bb3c44f71e03482117670/shampoo.csv

    • @deehanchowdhury1230
      @deehanchowdhury1230 6 лет назад

      Actually i solved it in a naive way....using for loop and checking for values ~=0, if this condition was satisfied then i copied data in a new vector.

  • @musafir1068
    @musafir1068 6 лет назад

    plz do it for cubic spline

  • @wafaaali8974
    @wafaaali8974 3 года назад

    Please give me away program the solve of the linear and quadratic splines please.

    • @CarlosMontalvo251
      @CarlosMontalvo251  3 года назад +1

      All my codes on splines are in this folder as of 6/14/2021
      github.com/cmontalvo251/MATLAB/tree/master/Screen_Cast_Codes/Interpolation

    • @wafaaali8974
      @wafaaali8974 3 года назад

      @@CarlosMontalvo251 thank you so much 🌹🌹

  • @sa.75-kin_
    @sa.75-kin_ 3 года назад

    Can you email