matlab learning - 05 interpolation and fitting (Xiaolangdi water and sediment regulation issues)

05 Interpolation and Fitting

Xiaolangdi water and sediment regulation issues

 

data3.txt

1800    1900    2100    2200    2300    2400    2500    2600    2650    2700    2720    2650
32    60    75    85    90    98    100    102    108    112    115    116
2600    2500    2300    2200    2000    1850    1820    1800    1750    1500    1000    900
118    120    118    105    80    60    50    30    26    20    8    5

 

Interpolation

One problem% 
% v: water flow S: sediment concentration; V:? Sand amount 
% assumed water flow and sediment concentration are continuous, a certain amount of time Sand V = v (t) S ( t) 
% first known water flow and sediment concentration some time, given the estimated amount of sediment at any time and the total sediment volume 
% of the total amount of sediment is the amount of sediment to do integration 
% of the time 8: 00-20: 00 = 28800 T1, T2 = T24 = 1.0224 million 
the format Compact; 
CLC, Clear; 
Load data3.txt 
Liu DATA3 = ([l, 3], :); Liu = Liu '; Liu = Liu (:);% and made water flow order column vectors into 
sha = data3 ([2,4], :); sha = sha '; sha = sha (:);% silt content and presented in order into a column vector 
y = sha * liu.; y = y ';% Sand calculated amount into a row vector 
I =. 1: 24; 
T = (I-12 is *. 4) 3600 *; 
T1 = T (. 1); T2 = T (End); 
% interpolation 
pp = csape (t, y); % cubic spline interpolation 
xsh = pp.coefs% calculated interpolation polynomial coefficient matrix, each row is a section on the coefficients of the polynomial 
TL = quadl (@ (tt) fnval (pp, tt ), t1, t2)% of the total required amount of integral calculation Sand 
% visual display interpolation polynomial and the old value 
t0 = t1: 0.1: t2; 
y0 = fnval (pp, t0) ;
plot(t,y,'+',t0,y0)
xsh = 
   1.0e + 05 * 
   -0.0000 -0.0000 0.00008 0.5760 
   -0.0000 -0.0000 0.00008 1.1400 
   -0.0000 -0.0000 0.00008 1.5750 
    0.00008 -0.0000 0.00008 1.8700 
   -0.0000 0.00008 0.00008 2.0700 
    0.00008 -0.0000 0.00008 2.3520 
    0.00008 0.00008 0.00008 2.5000 
   -0.0000 0.00008 0.00008 2.6520 
    0.00008 -0.0000 0.00008 2.8620 
   -0.0000 0.00008 0.00008 3.0240 
    0.00008 -0.0000 0.00008 3.1280 
   -0.0000 0.00008 -0.0000 3.0740 
   -0.0000 -0.0000 0.00008 3.0680 
    0.00008 -0.0000 -0.0000 3.0000 
   -0.0000 0.00008 -0.0000 2.7140
    0.0000   -0.0000   -0.0000    2.3100
    0.0000    0.0000   -0.0000    1.6000
   -0.0000    0.0000   -0.0000    1.1100
    0.0000   -0.0000   -0.0000    0.9100
   -0.0000    0.0000   -0.0000    0.5400
    0.0000   -0.0000   -0.0000    0.4550
    0.0000   -0.0000   -0.0000    0.3000
    0.0000    0.0000   -0.0000    0.0800
TL =
   1.8440e+11

 

Fit

% Second problem: determine the relationship between water flow and the amount of Sediment 
the format Compact; 


% Sediment volume and draw water flow scattergram 
CLC, Clear; 
Load data3.txt 
Liu DATA3 = ([l, 3], :); liu = liu '; liu = liu (:);% is proposed in order to become the water flow and the column vector 
sha = data3 ([2,4], :); sha = sha'; sha = sha (:);% proposed sediment concentration and order into a column vector 
y = sha * liu;.% calculated amount desilting, there is a column vector 
subplot (1,2,1), plot (liu (1:11), y (1:11 ), '*') 
the subplot (1,2,2), Plot (Liu (12:24), Y (12:24), '*') 


% of the first stage is substantially linear 
% of the first stage and are prepared by a two-stage quadratic curve fit and 
the remaining standards% which model to select a small difference which model 
the format Long E 

% or less of the first stage fitting 
for J =. 1: 2 
    nihe1 polyfit {J} = (Liu (1:11), y (1:11) , j);% fit polynomial coefficients arranged from a low power to higher power 
    yhat1 {j} = polyval (nihe1 {j}, liu (1:11)) ;% determine a predicted value 
    cha1 (j) = sum (( y (1:11) -yhat1 {j}) ^ 2.);% seeking squared error
    rmse1 (j) = sqrt (cha1 (j) / (10-j));% residual standard deviation request 
End 
celldisp (nihe1)% all elements of the array cells 
rmse1 

% or less of the second phase of fitting 
for j = 1 : 2 
    nihe2 polyfit {J} = (Liu (12:24), Y (12:24), (J));% using cell array 
    yhat2 {j} = polyval (nihe2 {j}, liu (12:24) );% determine a predicted value 
    cha2 (j) = sum (( y (12:24) -yhat2 {j}) ^ 2);.% seek error squared and 
    rmse2 (j) = sqrt (cha2 (j) / (11 -j));% residual standard deviation request 
End 
celldisp (nihe2)% all elements of the array cells 
rmse2 
the format% recovery default number display format short 


% final result 
% a: Y = 250.5655v-373,384.4661 
% two: y = 0.167 v * 2-180.4668v + 72421.0982

 

Guess you like

Origin www.cnblogs.com/caiyishuai/p/11404773.html