Väliskaubandusbilansi näide

Remove["Global`*"]

Andmed Statistikaameti andmebaasist

solmex  = {{1993, 10222.3}, {1994, 16927.3}, {1995, 21071.6}, {1996, 
            25036.6}, 
{1997, 40789.6}, {1998, 
            45576.4}, {1999, 43991}, {2000, 
            65193.2}, 
{2001, 70118}, {2002, 
            71752.7}, {2003, 77671.5}, {2004, 
            74614.3}, 
{2005, 96747.4}, {2006, 
            119427.1}};

solmimp  = {{1993, 11400.9}, {1994, 21484.9}, {1995, 
            29119.5}, {1996, 38885.2}, {1997, 61662.9}, {1998, 
            67379.3}, {1999, 60492.5}, {2000, 86118.4}, {2001, 
            91356.9}, {2002, 96885.8}, {2003, 109624.3}, {2004, 
            104881.3}, {2005, 128435.5}, {2006, 161933.6}};

solmdeficit = {{1993, 1178.6}, {1994, 4557.6}, {1995, 8047.9}, {1996, 
            13848.6}, {1997, 20873.3}, {1998, 21802.9}, {1999, 
            16501.5}, {2000, 20925.2}, {2001, 21238.9}, {2002, 
            25133.2}, {2003, 31952.8}, {2004, 30267.1}, {2005, 
            31688.2}, {2006, 42506.5}};

Punktid ja väärtused

exppoints  =  
        Graphics[{
AbsolutePointSize[2], 
            RGBColor[0, 0, 0.5], 
            Map[Point, solmex]}];
imppoints  =  
        Graphics[{
AbsolutePointSize[2], 
            RGBColor[0.5, 0, 0], 
            Map[Point, solmimp]}];
defpoints  =  
        Graphics[{
AbsolutePointSize[2], 
            RGBColor[0, 0.5, 0], Map[Point, solmdeficit]}];

aastad = Transpose[
            solmex][[1]];
expvaart = Transpose[
            solmex][[2]];
impvaart = Transpose[
            solmimp][[2]];
defvaart = Transpose[
            solmdeficit][[2]];

Punktid graafikul:

Show[exppoints, imppoints,  Axes -> True]

<<Graphics`MultipleListPlot`

MultipleListPlot[solmex, solmimp,PlotLegend -> {"Export", "Import"},
     PlotJoined -> True,AxesOrigin->{1992,0}]

MultipleListPlot[solmex, solmimp,
  PlotStyle -> {GrayLevel[0], Dashing[{Dot, Dash}]},
  SymbolShape -> {PlotSymbol[Triangle], PlotSymbol[Box]},
  SymbolStyle -> {GrayLevel[0], GrayLevel[0.5]}]

Interpolatsioonipolünoomid

pol1=InterpolatingPolynomial[solmex, x]

explagrange = 
      Plot[pol1, {x, 1992, 2006.5}, PlotRange -> {-96000, 259000}, 
        PlotStyle -> RGBColor[0, 0, 1]]

pol2=InterpolatingPolynomial[solmimp, x]

implagrange = 
      Plot[pol2, {x, 1992, 2006.5}, 
        PlotRange  -> {-180000, 400000}, 
        PlotStyle -> RGBColor[1, 0, 0]]

Show[implagrange, explagrange, imppoints, exppoints]

Vähimruutude meetod

x =.

pex = 
      Fit[solmex, {1, x, x^2, x^3, x^4, x^2, x^3, x^4, x^5, x^6, x^7}, 
        x]

pimp = 
      Fit[solmimp, {1, x, x^2, x^3, x^4, x^2, x^3, x^4, x^5, x^6, x^7}, 
        x]

Plot[pex, {x, 1992, 2007}, 
      Epilog -> {PointSize[0.01], 
          Point /@ solmex}, 
PlotStyle -> 
        RGBColor[0, 0, 1]]

Plot[{pimp, pex}, {x, 1992, 2007}, PlotRange -> {0, 168000}, 
      Epilog -> {{PointSize[0.01],  Hue[0.01], 
            Point /@ solmimp}, {PointSize[0.01],  Hue[0.6], 
            Point /@ solmex}}, 
PlotStyle -> {RGBColor[
            1, 0, 0], RGBColor[0, 0, 1]}]

NSolve[pimp == pex, x]

x = 2006;  pimp

x = 2006;  pex

Interpoleerimine kuupsplainidega (sisseehitatud meetod)

<< NumericalMath`SplineFit`

expspl = SplineFit[solmex, Cubic]

gr1 = 
        ParametricPlot[expspl[t], {t, 0, 13}, 
          PlotStyle -> RGBColor[0, 0, 1], 
          Compiled -> False];

impspl = SplineFit[solmimp, Cubic]

gr2 = 
        ParametricPlot[impspl[t], {t, 0, 13}, 
          PlotStyle -> RGBColor[1, 0, 0], 
          Compiled -> False];

kuupsplainid = Show[gr1, gr2, exppoints, imppoints]

Lineaarsplainidega interpoleerimine (isetehtud meetod)

Eksport

n = Length[solmex] - 1;
Do[x[i] = solmex[[i + 1, 1]]; 
      y[i] = solmex[[i + 1, 2]], {i, 0, 
        n}]

Lineaarsplain

S[i_][x_] := c[0, i] + c[1, i] x;
tingimused = 
        Table[{S[i][x[i]] == y[i], S[i + 1][x[i]] == y[i]}, {i, 1, 
            n - 1}];
AppendTo[
        tingimused, {S[1][x[0]] == y[0], S[n][x[n]] == 
            y[n]}];
TableForm[tingimused = Flatten[tingimused]]

kordajad = First[Solve[tingimused]]

funs = 
      Table[S[i][x], {i, n}] /. kordajad

splainexp = 
        Table[Plot[
            funs[[i]], {x, x[i - 1], 
              x[i]}, PlotStyle -> 
              RGBColor[0, 0, 1], 
DisplayFunction -> 
              Identity], {i, 1, n}];
lineaarsplexp = 
        Show[splainexp, exppoints, 
          DisplayFunction -> $DisplayFunction];

Import

n = Length[solmimp] - 1;
Do[x[i] = solmimp[[i + 1, 1]]; 
      y[i] = solmimp[[i + 1, 2]], {i, 0, 
        n}]

Lineaarsplain

S[i_][x_] := c[0, i] + c[1, i] x;
tingimused = 
        Table[{S[i][x[i]] == y[i], S[i + 1][x[i]] == y[i]}, {i, 1, 
            n - 1}];
AppendTo[
        tingimused, {S[1][x[0]] == y[0], S[n][x[n]] == 
            y[n]}];
TableForm[tingimused = Flatten[tingimused]]

kordajad = First[Solve[tingimused]]

funs = 
      Table[S[i][x], {i, n}] /. kordajad

splainimp = 
        Table[Plot[
            funs[[i]], {x, x[i - 1], 
              x[i]}, PlotStyle -> 
              RGBColor[1, 0, 0], 
DisplayFunction -> 
              Identity], {i, 1, n}];
lineaarsplimp = 
        Show[splainimp, imppoints, 
          DisplayFunction -> $DisplayFunction];

lineaarsplainid = 
      Show[splainexp, splainimp, exppoints, imppoints, 
        DisplayFunction -> $DisplayFunction]

Lineaarsplainid ja kuupsplainid kõik ühel joonisel

Show[gr1, gr2, lineaarsplainid]

Tükati-lineaarne interpoleerimine

expgrlin = 
      ListInterpolation[expvaart, {aastad}, 
        InterpolationOrder -> 1]

exptyklin = Plot[expgrlin[x], {x, 1993, 2006}];

impgrlin = 
      ListInterpolation[impvaart, {aastad}, 
        InterpolationOrder -> 1]

imptyklin = Plot[impgrlin[x], {x, 1993, 2006}];

Show[exptyklin, imptyklin, exppoints, imppoints];

Tükati-kuupinterpoleerimine

expgrkuup = 
      ListInterpolation[expvaart, {aastad}, 
        InterpolationOrder -> 3]

exptykkuup = 
        Plot[expgrkuup[x], {x, 1993, 2006}, 
          PlotStyle -> RGBColor[0, 0, 1]];

impgrkuup = 
      ListInterpolation[impvaart, {aastad}, 
        InterpolationOrder -> 3]

imptykkuup = 
        Plot[impgrkuup[x], {x, 1993, 2006}, 
          PlotStyle -> RGBColor[1, 0, 0]];

Show[exptykkuup, imptykkuup, exppoints, imppoints];

Show[exptykkuup, imptykkuup, gr1, gr2, exppoints, 
        imppoints];

Tulemus - tükati interpoleerimine kuupfunktsioonidega töötab paremini kui interpoleerimine kuupsplainidega