Kurs Komputerowy S System Symboliczny Mathematica Obliczenia numeryczne Dokladnosc i precyzja Precision[wartosc] SetPrecision[wartosc, precyzja] Accuracy[wartosc] SetAccuracy[wartosc, dokladnosc] MachinePrecision In[1]:= a Sqrt Out[1]= In[]:= Precision a Out[]= In[]:= Precision 1. Out[]= MachinePrecision
0-obliczenia numeryczne.nb In[]:= b 1. 0 Out[]= 1.000000000000000000000000000000000000000000000000 In[]:= Precision b Out[]= 0. In[6]:= b Sqrt. Out[6]= 1.11 In[7]:= Precision b Out[7]= MachinePrecision In[8]:= $MachinePrecision Out[8]= 1.96 In[9]:= c SetPrecision b, 0 Out[9]= 1.1167091 In[10]:= Precision c Out[10]= 0. In[11]:= Accuracy c Out[11]= 19.89 In[1]:= Accuracy 1. Out[1]= 1.806
0-obliczenia numeryczne.nb In[1]:= d 1. 0 Out[1]= 1.000000000000000000000000000000000000000000000000 In[1]:= Accuracy d Out[1]= 0. Wynik dokladny a przyblizony wyrazenie // N N[wyrazenie] N[wyrazenie, precyzja] Chop[wyrazenie] In[1]:= a Sqrt Out[1]= In[16]:= b Sqrt. Out[16]= 1.11 In[17]:= a N Out[17]= 1.11 In[18]:= Precision Out[18]= MachinePrecision In[19]:= N a, 0 Out[19]= 1.116709088016887096980786967187769
0-obliczenia numeryczne.nb In[0]:= Precision Out[0]= 0. In[1]:= Chop 1. Out[1]= 1. In[]:= Chop 0.90 10^ 10 Out[]= 0 In[]:= Chop 1.0 10^ 0 Out[]= 0 In[]:= 1.0 10^ 0 Out[]= 1. 10 0 In[]:= Fourier 1, 0,, 0, 7, 0, 6,, 1 Out[]= 7. 0.,.19876 1.76, 1.0196 0.1006, 0.166667.007, 1.17.9968, 1.17.9968, 0.166667.007, 1.0196 0.1006,.19876 1.76 In[6]:= InverseFourier Out[6]= 1.,.9119 10 16,., 0., 7., 7.019 10 16, 6.,., 1. In[7]:= Chop Out[7]= 1., 0,., 0, 7., 0, 6.,., 1. Suma i iloczyn elementow ciagu NSum[wyrazenie, {zmienna, w_pocz, w_konc}] NProduct[wyrazenie, {zmienna, w_pocz, w_konc}]
0-obliczenia numeryczne.nb Options[polecenie] In[8]:= NSum 1 x, x, 1, 100 Out[8]= 1.698 In[9]:= NSum 1 x, x, 1, Infinity Out[9]= 1.69 In[0]:= Sum 1 x, x, 1, Infinity Out[0]= Π 6 In[1]:= N Out[1]= 1.69 In[]:= Options NSum Out[]= AccuracyGoal, Compiled Automatic, EvaluationMonitor None, Method Automatic, NSumTerms 1, PrecisionGoal Automatic, VerifyConvergence True, WorkingPrecision MachinePrecision In[]:= NSum 1 x, x, 1, Infinity, WorkingPrecision 0 Out[]= 1.6906688667116611760016611 In[]:= NSum 1 x, x, 1, Infinity, PrecisionGoal 0, WorkingPrecision 0 NIntegrate::ncvb : NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in x near x 0.1780798917980. NIntegrate obtained 0.06 0. and 9.07911618 0.*^- for the integral and error estimates. Out[]= 1.690668866 In[]:= Precision Out[]= 0.
6 0-obliczenia numeryczne.nb In[6]:= NSum 1 x, x, 1, 10, EvaluationMonitor : Print "x ", x, " ", N 1 x, 10 x 1. 1. x. 0. x. 0.111111 x. 0.06 x. 0.0 x 6. 0.077778 x 7. 0.0008 x 8. 0.016 x 9. 0.017 x 10. 0.01 Out[6]= 1.977
0-obliczenia numeryczne.nb 7 In[7]:= NSum 1 x, x, 1, 10, WorkingPrecision 0, EvaluationMonitor : Print "x ", x, " ", N 1 x, 10 x 1.0000000000000000000000000000000000000000000000000 1.000000000 x.0000000000000000000000000000000000000000000000000 0.00000000 x.0000000000000000000000000000000000000000000000000 0.1111111111 x.0000000000000000000000000000000000000000000000000 0.060000000 x.0000000000000000000000000000000000000000000000000 0.0000000000 x 6.0000000000000000000000000000000000000000000000000 0.0777777778 x 7.0000000000000000000000000000000000000000000000000 0.0008167 x 8.0000000000000000000000000000000000000000000000000 0.01600000 x 9.0000000000000000000000000000000000000000000000000 0.0167901 x 10.000000000000000000000000000000000000000000000000 0.01000000000 Out[7]= 1.976771166069001197796961778788809 In[8]:= NProduct x x 1, x, 1, 100 Out[8]= 0.00990099 In[9]:= Product x x 1, x, 1, 100 Out[9]= 1 101 In[0]:= N Out[0]= 0.00990099
8 0-obliczenia numeryczne.nb In[1]:= Options NProduct Out[1]= AccuracyGoal, Compiled Automatic, EvaluationMonitor None, Method Automatic, NProductFactors 1, PrecisionGoal Automatic, VerifyConvergence True, WorkingPrecision MachinePrecision Rozwiazywanie rownan NSolve[rown, zmienna] (* NSolve[...] N[Solve[...]] *) In[]:= eq x x 0 NSolve eq, x Out[]= x x 0 Out[]= x.67, x 0.671 In[]:= Solve eq, x Out[]= x 7, x 7 In[]:= N Out[]= x.67, x 0.671 In[6]:= Clear a, b, c In[7]:= NSolve a x b x c 0, x Out[7]= x 0. 1. b 1. b. a c a, x 0. 1. b b. a c a
0-obliczenia numeryczne.nb 9 FindRoot[wielomian, zmienna] In[8]:= f x x x x 1 FindRoot f, x, 1 Out[8]= 1 x x x x Out[9]= x 1.10 In[0]:= FindRoot f, x, 0 Out[0]= x 0.191 In[1]:= FindRoot f, x, 1 Out[1]= x 1.116 In[]:= Plot f, x,, Out[]= 1 1 10 Interpolacja, ekstrapolacja i aproksymacja Interpolation[dane] dane: {f1, f, f,...} {{x1, f1}, {x, f}, {x, f},...} {{{x1, y,...}, f1}, {{x, y,...}, f},...} Interpolation[dane,wartosc]
10 0-obliczenia numeryczne.nb In[]:= d 1,,, 6,, 7,, 8 fi Interpolation d Out[]= 1,,, 6,, 7,, 8 Out[]= InterpolatingFunction 1, 8, In[]:= fi fi. Out[]= Out[6]=. In[7]:= fi 10 InterpolatingFunction::dmval : Input value 10 lies outside the range of data in the interpolating function. Extrapolation will be used. Out[7]= 9 In[8]:= Plot fi x, x, 1, 8 8 7 6 Out[8]=
0-obliczenia numeryczne.nb 11 In[9]:= Show, ListPlot d 8 7 6 Out[9]= In[60]:= d 1, 1,,,,,, 6, 6,, 8, 7, 9,, 11, 8 fi Interpolation d Out[60]= 1, 1,,,,,, 6, 6,, 8, 7, 9,, 11, 8 Out[61]= InterpolatingFunction 1, 11, In[6]:= Show Plot fi x, x, 1, 11, ListPlot d 7 6 Out[6]= In[6]:= Options Interpolation Out[6]= InterpolationOrder, Method Automatic, PeriodicInterpolation False
1 0-obliczenia numeryczne.nb In[6]:= d 1,,, 6,, 7,, 8 f0 Interpolation d, InterpolationOrder 0 ; f1 Interpolation d, InterpolationOrder 1 ; f Interpolation d, InterpolationOrder ; f Interpolation d, InterpolationOrder ; f Interpolation d, InterpolationOrder ; f Interpolation d, InterpolationOrder ; Out[6]= 1,,, 6,, 7,, 8 In[71]:= GraphicsGrid Plot f0 x, x, 1, 8, Plot f1 x, x, 1, 8, Plot f x, x, 1, 8, Plot f x, x, 1, 8, Plot f x, x, 1, 8, Plot f x, x, 1, 8 8 7 6 8 7 6 8 7 6 Out[71]= 6 7 8 6 7 8 6 7 8 8 7 6 8 7 6 8 7 6 Fit[dane, funkcja, zmienna] In[7]:= d 1,,, 6,, 7,, 8 ; f1 Fit d, 1, x, x f Fit d, 1, x, x, x f Fit d, 1, x, x, x, x, x f7 Fit d, 1, x, x, x, x, x, x 6, x 7, x Out[7]= 1. 0.666667 x Out[7]= 1. 0.666667 x.716 10 17 x Out[7]=..0808 x 0.9 x 0.0707071 x.61 10 16 x Out[76]=. 1081.7 x 999.6 x 68.8 x 1. x 18.0 x 1. x 6 0.0 x 7
0-obliczenia numeryczne.nb 1 In[77]:= GraphicsGrid Show Plot f1, x, 0, 9, PlotRange 0, 9,, 1, ListPlot d, Show Plot f, x, 0, 9, PlotRange 0, 9,, 1, ListPlot d, Show Plot f, x, 0, 9, PlotRange 0, 9,, 1, ListPlot d, Show Plot f7, x, 0, 9, PlotRange 0, 9,, 1, ListPlot d 1 1 10 10 0 6 8 0 6 8 Out[77]= 1 1 10 10 0 6 8 0 6 8 In[78]:= Fit 1, 1, x, x, x Out[78]= 0. 0. x 0. x FindFit[dane, funkcja, parametry, zmienna] FindFit[dane,{funkcja,warunki},parametry,zmienna] In[80]:= Clear f In[81]:= f De_, Α_, xe_ : De 1 Exp Α x xe In[8]:= funkcja f, 0., Out[8]= 1 0. x
1 0-obliczenia numeryczne.nb In[8]:= Plot funkcja, x, 0, 10 Out[8]= 1 In[8]:= dane Table x, funkcja, x, 1, 10 Out[8]= 1,.9098,, 0.81679,, 0.,, 0.0966,, 0.7991, 6, 1.070, 7, 1.99, 8, 1.681, 9, 1.8081, 10, 1.8810 In[8]:= ff Fit dane, 1, x, x, x, x, x Out[8]= 1.691 11.9016 x.70 x 0.879 x 0.018087 x In[86]:= Show Plot ff, x, 1, 10, ListPlot dane Out[86]= 1 6 8 10
0-obliczenia numeryczne.nb 1 In[87]:= ffit FindFit dane, a 1 Exp b x c ^, a, b, c, x Out[87]= a 1.998, b.118, c 1.807 In[88]:= Show Plot f a, b, c. ffit, x, 1, 10, ListPlot dane.0..0 Out[88]= 1. 1.0 0. In[89]:= ffit FindFit dane, a 1 Exp b x c ^, b 0., a, b, c, x Out[89]= a.000, b 0.9998, c.00016 In[90]:= Show Plot f a, b, c. ffit, x, 1, 10, ListPlot dane Out[90]= 1 Minimum i maksimum funkcji FindMinimum[funkcja, {zmienna, wartosc}]
16 0-obliczenia numeryczne.nb NMinimize[funkcja,zmienna] FindMaximum[funkcja,{zmienna,wartosc}] NMaximize[funkcja,zmienna] Opcje: StepMonitor i EvaluationMonitor In[91]:= f x x x x 1 Plot f, x,, Out[91]= 1 x x x x 0 Out[9]= 0 1 1 0 In[9]:= f x x x x 1 FindMinimum f, x, 0 Out[9]= 1 x x x x FindMinimum::lstol : The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. Out[9]= 1.8777, x 0.787 In[9]:= FindMinimum f, x, Out[9]= 9.696, x.1906 In[96]:= FindMinimum f, x, Out[96]= 9.696, x.1906
0-obliczenia numeryczne.nb 17 In[97]:= NMinimize f, x Out[97]= 9.696, x.1906 In[98]:= Options NMinimize Out[98]= AccuracyGoal Automatic, EvaluationMonitor None, MaxIterations 100, Method Automatic, PrecisionGoal Automatic, StepMonitor None, WorkingPrecision MachinePrecision In[99]:= NMinimize f, x, Method "DifferentialEvolution" Out[99]= 9.696, x.1906 In[100]:= FindMaximum f, x, 0 Out[100]=.701, x 0.7818 In[101]:= FindMaximum f, x, 1 FindMaximum::cvmit : Failed to converge to the requested accuracy or precision within 100 iterations. Out[101]=.770098 10 17, x.761 10 10 In[10]:= NMaximize f, x NMaximize::cvdiv : Failed to converge to a solution. The function may be unbounded. Out[10]=.7696886677 10, x 1.768 10 106
18 0-obliczenia numeryczne.nb In[10]:= i 1; FindMinimum f, x, 0, StepMonitor : Print "i ", i, " x ", x ; i i 1 x 0. i x 0.6891 i x 0.7196 i x 0.77817 i x 0.789 i 6 x 0.787 i 7 x 0.787 FindMinimum::lstol : The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. Out[10]= 1.8777, x 0.787
0-obliczenia numeryczne.nb 19 In[10]:= i 1; FindMinimum f, x, 0, EvaluationMonitor : Print "i ", i, " x ", x ; i i 1 x 0. i x 0. i x 1.66667 i x 0.6891 i x 0.7196 i 6 x 0.77817 i 7 x 0.789 i 8 x 0.787 i 9 x 0.787 i 10 x 0.787 i 11 x 0.787 i 1 x 0.787 i 1 x 0.787 i 1 x 0.787 i 1 x 0.787 FindMinimum::lstol : The line search decreased the step size to within the tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the function. You may need more than MachinePrecision digits of working precision to meet these tolerances. Out[10]= 1.8777, x 0.787 Calkowanie NIntegrate[funkcja, {zmienna, w_pocz, w_konc}]
0 0-obliczenia numeryczne.nb In[10]:= NIntegrate Sin x, x, 0, 1 Out[10]= 0.9698 In[106]:= Options NIntegrate Out[106]= AccuracyGoal, Compiled Automatic, EvaluationMonitor None, Exclusions None, MaxPoints Automatic, MaxRecursion Automatic, Method Automatic, MinRecursion 0, PrecisionGoal Automatic, WorkingPrecision MachinePrecision In[107]:= NIntegrate Sin x ^ Cos y^, x, 0, Pi, y, 0, Pi Out[107]= 0.66691 Rozwiazywanie rownan rozniczkowych NDSolve[{rownanie,warunki}, funkcja,{zmienna, w_pocz, w_konc}] In[109]:= DSolve y x Cos x, y x, x Out[109]= y x C 1 Sin x In[110]:= r DSolve y x Cos x, y 0 1, y x, x Out[110]= y x 1 Sin x In[111]:= f y x. r 1 Out[111]= 1 Sin x In[11]:= Table f, x, 0, 10 N Out[11]= 1., 1.817, 1.909, 1.111, 0.198, 0.01077, 0.708, 1.6699, 1.9896, 1.11, 0.979
0-obliczenia numeryczne.nb 1 In[11]:= nr NDSolve y x Cos x, y 0 1, y, x, 0, 10 Out[11]= y InterpolatingFunction 0., 10., In[11]:= Table y x. nr 1, x, 0, 10 Out[11]= 1., 1.817, 1.9099, 1.111, 0.198, 0.01077, 0.708, 1.6698, 1.989, 1.11, 0.979 In[11]:= Plot f, y x. nr 1, x, 0, 10.0 1. Out[11]= 1.0 0. In[116]:= Options NDSolve Out[116]= AccuracyGoal Automatic, Compiled Automatic, DependentVariables Automatic, EvaluationMonitor None, InterpolationOrder Automatic, MaxStepFraction 1 10, MaxSteps 10 000, MaxStepSize Automatic, Method Automatic, NormFunction Automatic, PrecisionGoal Automatic, SolveDelayed Automatic, StartingStepSize Automatic, StepMonitor None, WorkingPrecision MachinePrecision