Cubic Spline method for extrapolation in MatLab -
i'm trying predict value @ next time step of sinusoidal waveform. i'm using cubic spline extrapolation found in web page.
http://mathworld.wolfram.com/cubicspline.html
the following matlab code used.
clear all;close v0_mag=230*sqrt(2/3); t1=0;dt=50e-6; h=dt; h=[4 1 0;1 4 1;0 4 1]; invh=inv(h); y = zeros(3,1); w0=2*pi*60;a=0;b=0;c=0;d=0; t=1; m=1:0.2/dt t11(m)=t1; y(m,1)=v0_mag*(1-exp(-20*t11(m)))*sin(w0*t11(m)); %cubic splines method n=3 if m>5 y(3,1)=3*(y(m-2)-y(m-3)); end if m>4 y(3,1)=3*(y(m-1)-y(m-2)); end if m>3 y(3,1)=3*(y(m)-y(m-1)); end d=(invh*y); ax(m)=a; if m>1 a=y(m-1);b=d(2); c=3*(y(m)-y(m-1))-(2*d(2)+d(3)); d=2*(-y(m)+y(m-1))+d(2)+d(3); end prey1(m,1)=d*(t)^3+c*(t)^2+b*(t)+a; t1=t1+dt; end figure(1) plot(t11,prey1) hold on plot(t11,y,'r') legend
this code works 0<t<1
(interpolation). extrapolate have make t>1. , when put t=2 (that means i'm trying find value @ next time step) waveforms not match. can me how extrapolation using code.
Comments
Post a Comment