ModelMath Empiris Regresi Linear Nonlinear 2023
ModelMath Empiris Regresi Linear Nonlinear 2023
5<<;
y = Fit@Data, 81, x<, xD
Plot@y, 8x, 1, 7<, Epilog ® 8PointSize@LargeD, Point@DataD<,
AxesLabel ® 8"x", "y"<, AxesOrigin ® 80, 0<D
0.0714286 + 0.839286 x
y
6
x
1 2 3 4 5 6 7
Data = 881, 3<, 84, 5<, 85, 6<, 86, 8<, 87, 8<<;
f@anydata_D := If@Length@anydataD == 1, anydata@@1, 2DD, If@Length@anydataD == 2,
Hanydata@@2, 2DD - anydata@@1, 2DDL Hanydata@@2, 1DD - anydata@@1, 1DDL,
Hf@Drop@anydata, 1DD - f@Drop@anydata, - 1DDL
Hanydata@@Length@anydataD, 1DD - anydata@@1, 1DDLDD;
NP@anydata_D := Sum@f@anydata@@1 ;; iDDD * Product@Hx - anydata@@j, 1DDL,
8j, 1, i - 1<D, 8i, 1, Length@anydataD<D;
H*Using the Newton polynomial function*L
y = Expand@NP@DataDD
H*Using the interpolating polynomial built-in function*L
y2 = Expand@InterpolatingPolynomial@Data, xDD
32 775 x 677 x2 59 x3 7 x4
- + - + -
3 36 72 36 72
32 775 x 677 x2 59 x3 7 x4
- + - + -
3 36 72 36 72
Data = 881, 3<, 84, 5<, 85, 6<, 86, 8<, 87, 8<<;
Lagrange@anydata_D :=
Sum@anydata@@i, 2DD * LP@anydata, iD, 8i, 1, Length@anydataD<D
LP@anydata_, i_D := Hnewdata = Drop@anydata, 8i<D;
Product@Hx - newdata@@j, 1DDL Hanydata@@i, 1DD - newdata@@j, 1DDL,
8j, 1, Length@newdataD<DL
H*Using the Lagrange polynomial function*L
y = Expand@Lagrange@DataDD
H*Using the interpolating polynomial built-in function*L
y2 = Expand@InterpolatingPolynomial@Data, xDD
32 775 x 677 x2 59 x3 7 x4
- + - + -
3 36 72 36 72
32 775 x 677 x2 59 x3 7 x4
- + - + -
3 36 72 36 72
2 ModelMath_Empiris_Regresi_Linear_Nonlinear_2023.nb
Clear@a, b, xD
Data = 881, 0.5<, 82, 2.5<, 83, 2<, 84, 4.0<, 85, 3.5<, 86, 6.0<, 87, 5.5<<;
LinearFit@Data_D := Hn = Length@DataD;
a = Hn * Sum@Data@@i, 1DD * Data@@i, 2DD, 8i, 1, n<D -
Sum@Data@@i, 1DD, 8i, 1, n<D * Sum@Data@@i, 2DD, 8i, 1, n<DL
Hn * Sum@Data@@i, 1DD ^ 2, 8i, 1, n<D - HSum@Data@@i, 1DD, 8i, 1, n<DL ^ 2L;
b = HSum@Data@@i, 2DD, 8i, 1, n<D - a * Sum@Data@@i, 1DD, 8i, 1, n<DL n;
RSquared = 1 - Sum@HData@@i, 2DD - a * Data@@i, 1DD - bL ^ 2, 8i, 1, n<D
Sum@HData@@i, 2DD - 1 n * Sum@Data@@j, 2DD, 8j, 1, n<DL ^ 2, 8i, 1, n<D;
8RSquared, a, b<L
LinearFit@DataD
RSquared = LinearFit@DataD@@1DD
a = LinearFit@DataD@@2DD
b = LinearFit@DataD@@3DD
y = a * x + b;
Plot@y, 8x, 1, 7<, Epilog -> 8PointSize@LargeD, Point@DataD<,
AxesLabel -> 8"x", "y"<, AxesOrigin -> 80, 0<D
80.868318, 0.839286, 0.0714286<
0.868318
0.839286
0.0714286
y
6
x
1 2 3 4 5 6 7
h = 0.1;
n = 2 h + 1;
y = 1 H1 + 25 x ^ 2L;
yp = D@y, xD;
ypp = D@yp, xD;
yppp = D@ypp, xD;
ypppp = D@yppp, xD;
Data = Table@8- 1 + h * Hi - 1L, Hy . x ® - 1 + h * Hi - 1LL<, 8i, 1, n<D;
FFD1h1@Data_D :=
Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD; f = Data@@All, 2DD;
Table@8Data@@i, 1DD, Hf@@i + 1DD - f@@iDDL h<, 8i, 1, n - 1<DL;
FFD1h2@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD;
Table@8Data@@i, 1DD, H- f@@i + 2DD + 4 f@@i + 1DD - 3 f@@iDDL 2 h<, 8i, 1, n - 2<DL;
ModelMath_Empiris_Regresi_Linear_Nonlinear_2023.nb 3
Table@8Data@@i, 1DD, Hf@@i + 1DD - 2 f@@iDD + f@@i - 1DDL h ^ 2<, 8i, 2, n - 1<DL;
CFD2h4@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD; Table@8Data@@i, 1DD,
H- f@@i + 2DD + 16 f@@i + 1DD - 30 f@@iDD + 16 f@@i - 1DD - f@@i - 2DDL 12 h ^ 2<, 8i,
3, n - 2<DL;
CFD3h2@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD; Table@8Data@@i, 1DD,
Hf@@i + 2DD - 2 f@@i + 1DD + 2 f@@i - 1DD - f@@i - 2DDL 2 h ^ 3<, 8i, 3, n - 2<DL;
CFD3h4@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD; Table@8Data@@i, 1DD, H- f@@i + 3DD + 8 f@@i + 2DD - 13 f@@i + 1DD +
13 f@@i - 1DD - 8 f@@i - 2DD + f@@i - 3DDL 8 h ^ 3<, 8i, 4, n - 3<DL;
CFD4h2@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD; Table@
8Data@@i, 1DD, Hf@@i + 2DD - 4 f@@i + 1DD + 6 f@@iDD - 4 f@@i - 1DD + f@@i - 2DDL h ^ 4<,
8i, 3, n - 2<DL;
CFD4h4@Data_D := Hn = Length@DataD; h = Data@@2, 1DD - Data@@1, 1DD;
f = Data@@All, 2DD;
Table@8Data@@i, 1DD, H- f@@i + 3DD + 12 f@@i + 2DD - 39 f@@i + 1DD + 56 f@@iDD -
39 f@@i - 1DD + 12 f@@i - 2DD - f@@i - 3DDL 6 h ^ 4<, 8i, 4, n - 3<DL;
ModelMath_Empiris_Regresi_Linear_Nonlinear_2023.nb 5
h = 0.2; h = 0.2;
n = 2 h + 1;
y = 1 H1 + 25 x ^ 2L;
yp = D@y, xD;
ypp = D@yp, xD;
yppp = D@ypp, xD;
ypppp = D@yppp, xD;
Data = Table@8- 1 + h * Hi - 1L, Hy . x -> - 1 + h * Hi - 1LL<, 8i, 1, n<D;
y2 = Interpolation@Data, Method -> "Spline", InterpolationOrder -> 1D;
ypInter = D@y2@xD, xD;
yppInter = D@y2@xD, 8x, 2<D;
ypppInter = D@y2@xD, 8x, 3<D;
yppppInter = D@y2@xD, 8x, 4<D;
Data1 = Table@8Data@@i, 1DD, HypInter . x -> Data@@i, 1DDL<, 8i, 1, n<D;
Data2 = Table@8Data@@i, 1DD, HyppInter . x -> Data@@i, 1DDL<, 8i, 1, n<D;
Data3 = Table@8Data@@i, 1DD, HypppInter . x -> Data@@i, 1DDL<, 8i, 1, n<D;
Data4 = Table@8Data@@i, 1DD, HyppppInter . x -> Data@@i, 1DDL<, 8i, 1, n<D;
a0 = Plot@8y, y2@xD<, 8x, - 1, 1<,
Epilog -> 8PointSize@LargeD, Point@DataD<, AxesLabel -> 8"x", "y"<,
BaseStyle -> Bold, ImageSize -> Medium, PlotRange -> All,
PlotLegends -> 8"y actual", "y spline"<, PlotLabel -> "First order splines"D;
a1 = Plot@8yp, ypInter<, 8x, - 1, 1<, Epilog -> 8PointSize@LargeD, Point@Data1D<,
AxesLabel -> 8"x", "y'"<, BaseStyle -> Bold, ImageSize -> Medium, PlotRange ->
All, PlotLegends -> 8"y'", "y'spline"<, PlotLabel -> "First derivative"D;
a2 = Plot@8ypp, yppInter<, 8x, - 1, 1<, Epilog -> 8PointSize@LargeD, Point@Data2D<,
AxesLabel -> 8"x", "y''"<, BaseStyle -> Bold, ImageSize -> Medium,
PlotRange -> All, PlotLegends -> 8"y''", "y''spline"<,
PlotLabel -> "Second derivative"D;
a3 = Plot@8yppp, ypppInter<, 8x, - 1, 1<, Epilog -> 8PointSize@LargeD, Point@Data3D<,
AxesLabel -> 8"x", "y''"<, BaseStyle -> Bold, ImageSize -> Medium,
PlotRange -> All, PlotLegends -> 8"y'''", "y'''spline"<,
PlotLabel -> "Third derivative"D;
a4 = Plot@8ypppp, yppppInter<, 8x, - 1, 1<,
Epilog -> 8PointSize@LargeD, Point@Data4D<, AxesLabel -> 8"x", "y''"<,
BaseStyle -> Bold, ImageSize -> Medium, PlotRange -> All,
PlotLegends -> 8"y''''", "y''''spline"<, PlotLabel -> "Fourth derivative"D;
Grid@88a0, a1<, 8a2, a3<, a4<D
First order splines
y
1.0
0.8
y actual
GridB:: 0.6 ,
y spline
0.4
0.2
x
-1.0 -0.5 0.5 1.0
6 ModelMath_Empiris_Regresi_Linear_Nonlinear_2023.nb
First derivative
y'
>,
1 y'
x y'spline
-1.0 -0.5 0.5 1.0
-1
-2
-3
Second derivative
y''
10
x
-1.0 -0.5 0.5 1.0
:
-10 y''
,
y''spline
-20
-30
-40
-50
Third derivative
y''
600
400
>,
200
y'''
x y'''spline
-1.0 -0.5 0.5 1.0
-200
-400
-600
>F
ModelMath_Empiris_Regresi_Linear_Nonlinear_2023.nb 7
Fourth derivative
y''
15 000
10 000
>F
y''''
5000 y''''spline
x
-1.0 -0.5 0.5 1.0
-5000