Start of the 1st lesson

1+1

sin

Sin

kyncl123
123kyncl

5 6

5 6

a=5

a=5;

a+1==4

1==1

ClearAll[a]
a+1==4

Sin[5]

Sin[5.]

(Sqrt[3.])

(Sqrt[2])

(Sqrt[2.])

(Sqrt[8])

N[Pi]
Pi//N
N@Pi

N[(Sqrt[2])]
(Sqrt[2])//N

((10!)/(13!))+((11!)/(14!))

N[(Sqrt[2])]
(Sqrt[2])//N
N@(Sqrt[2])

60!//N

Sin[Pi]

Plot[Sin[3x],{x,0,6Pi}]

Plot

Plot[Cos[(Sqrt[x])],{x,0,1000}]

?Plot

?=

a=2

?:=

a:=2
?a

a=Random[]

?a

a-a

{a,a,a,a,a}

a:=Random[]

?a

a-a

{a,a,a,a,a}

?_

ClearAll[f];
x=4;
f[x:_]:=(x^2);
f[5]

ClearAll[f];
x=4;
f[x_]:=(x^2);
f[5]
?f

ClearAll[f];
x=4;
f[x_]=(x^2);
f[1]
?f

?f

ClearAll[f,x];
f[x_]=(x^2);
?f
f[1]

ClearAll[f,x];
f[x_]=Integrate[x*Sin[(x^2)+1],x]
f[1.5]

ClearAll[f,x];
f[x_]:=Integrate[x*Sin[(x^2)+1],x]
f[1.5]

ClearAll[f];
f[x_]:=x;
f[x_Integer]:=(1/x);
f[5]="frog";
f[6]

$RecursionLimit=(10^4);
ClearAll[a];
a[n_]:=n*a[n-1];
a[0]:=1;
Timing[Table[a[i],{i,1000}]][[1]]
?a

ClearAll[a];
a[n_]:=a[n]=n*a[n-1];
a[0]:=1;
Timing[Table[a[i],{i,10}]][[1]]
?a;

Trace[a[3]];

Timing[Table[a[i],{i,10}]][[1]]

ClearAll[f];
f[{a_,b_}]:=a+b;
f[{a_,2}]:="error";
f[x_]:=1;
f[Plot[Sin[x],{x,0,1}]]

ClearAll[f];
f[x_]:=Module[{y,z,w},
y=(x^0.2);
z=Cos[y];
w=y+(1/z);
{y,z,w}
];
f[2]

ClearAll[f];
f[x_]:=Module[{y,z,w},
{y,z,w}
];
f[2]

Plot[Sin[x],{x,0,5}]

GoldenRatio//N

Plot[{Sin[x],Cos[2x]},{x,0,5},AspectRatio->(3/GoldenRatio)]

Options[Plot]

{AlignmentPoint->Center,AspectRatio->(1/GoldenRatio),Axes->True,AxesLabel->None,AxesOrigin->Automatic,AxesStyle->{},Background->None,BaselinePosition->Automatic,BaseStyle->{},ClippingStyle->None,ColorFunction->Automatic,ColorFunctionScaling->True,ColorOutput->Automatic,ContentSelectable->Automatic,CoordinatesToolOptions->Automatic,DisplayFunction:>$DisplayFunction,Epilog->{},Evaluated->Automatic,EvaluationMonitor->None,Exclusions->Automatic,ExclusionsStyle->None,Filling->None,FillingStyle->Automatic,FormatType:>TraditionalForm,Frame->False,FrameLabel->None,FrameStyle->{},FrameTicks->Automatic,FrameTicksStyle->{},GridLines->None,GridLinesStyle->{},ImageMargins->0.`,ImagePadding->All,ImageSize->Automatic,ImageSizeRaw->Automatic,LabelStyle->{},MaxRecursion->Automatic,Mesh->None,MeshFunctions->{#1&},MeshShading->None,MeshStyle->Automatic,Method->Automatic,PerformanceGoal:>$PerformanceGoal,PlotLabel->None,PlotLabels->None,PlotLegends->None,PlotPoints->Automatic,PlotRange->{Full,Automatic},PlotRangeClipping->True,PlotRangePadding->Automatic,PlotRegion->Automatic,PlotStyle->Automatic,PlotTheme:>$PlotTheme,PreserveImageOptions->Automatic,Prolog->{},RegionFunction->(True&),RotateLabel->True,ScalingFunctions->None,TargetUnits->Automatic,Ticks->Automatic,TicksStyle->{},WorkingPrecision->MachinePrecision}

Plot[Sin[(Sqrt[x])],{x,0,40Pi},AxesLabel->{"x","Sin[(Sqrt[x])]"},PlotStyle->{Thick,Blue,Dashed},GridLines->Automatic,PlotLabel->"Graph"]

?/.

teacher1+teacher2/.{teacher1->stupid,teacher2->ok}

(x^2)+y/.x->y

(x^2)+y/.{x->y,y->x}

x/.{{x->1},{x->2},{x->3}}

{a,b,c,t}[[2]]

sol=Solve[(x^3)==1.]
sol[[1]]
x1=x/.sol[[1]];

eqns={x+y==2b,2x+13y==(b^2)};
sol=Solve[eqns,{x,y}]

forPlot=((Sqrt[b])-(x^2)-(y^2)/.sol)//Simplify

Plot[forPlot,{b,1,2},PlotStyle->{Red,Thick},AxesLabel->{"b","forPlot"}]

Solve[a x+y==7&&b x-y==1,{x,y}]

Solve[{a x+y==7,b x-y==1},{x,y}]

DSolve[y'[x]+x*y[x]==x,y[x],x]

DSolve[{y'[x]+x*y[x]==x,y[0]==6},y[x],x]

ClearAll[y]

sol2=DSolve[{y'[t]+5*y[t]==Sin[t],y[0]==5},y[t],t]

fp=y[t]+0.1((y[t])^2)/.sol2

Plot[fp,{t,0,5},PlotStyle->{Blue},GridLines->Automatic,AxesLabel->{"t","forplot"}]

DSolve[{y'[x]+x*y[x]==x,y[0]==6},y[x],x]

ClearAll["Global`*"]
f[a_]:=x/.FindRoot[Cos[x]==a*x,{x,0}];
f[5]

ClearAll["Global`*"]
f[a_]:=x/.FindRoot[5+Sin[x]==a*x,{x,0}];

Plot[((f[a])/(1+((f[a])^2))),{a,1,2}]

ClearAll["Global`*"]
list={a,b,c,d};
TreeForm[list];
a+b+c+d//TreeForm;
list/.List->Plus

Range[100]/.List->Plus

LessEqual[2,2]

ClearAll["Global`*"];
f[x_]:=-x/;LessEqual[x,0];
f[x_]:=(x^2)/;x>0;
Plot[f[x],{x,-1,1}];

ClearAll["Global`*"];
f[x_]:=-x/;x≤0;
f[x_]:=(x^2)/;x>0;
Plot[f[x],{x,-1,1}];

ClearAll[f];
f[x_]:=1-(x^2)/;-1≤x≤1;
f[x_]:=f[x-2]/;x>1;
f[x_]:=f[x+2]/;x<-1;
Plot[f[x],{x,-5,5}];
Trace[f[5]];

pwf=Piecewise[{{x^2,x<0},{x,x>0}}];
Plot[pwf,{x,-2,2}]

fce[x_]:=-x/;x≤0;
fce[x_]:=1+x/;x≥0;
Plot[fce[x],{x,-1,1}];

(*pure functions*)

ClearAll[f]
f[x_]:=(x^2)
f[2]

((#)^2)&[2]

ff=((#1)^Pi)+((#2)^E)&
ff[2,3]

Select[{1,2,4,7,6,2},#>2&]

ClearAll[test];
test[x_]:=x>2;
Select[{1,2,4,7,6,2},test]

list={1,2,4,7,6,2};
Map[changeColor,list];
changeColor/@list;
((#)^3)&/@list;

Attributes[List]

Attributes[Sin]

Sin[list]
Sin/@list

list={you,me,he};
Apply[goForLunch,list]
goForLunch@@list

list={you,me,he};
TreeForm[list];
TreeForm[goForLunch[you,me,he]];

{a,b,c}//TreeForm;

Range[100]/.List->Plus;
Plus@@Range[100];

Plus@@(((#)^3)&/@Range[100]);
(∑_(i=1)^100)(i^3);

ClearAll[f];
f[x_?(#>2&)]:=1;
f[x_?(#≤2&)]:=-1;
Plot[f[x],{x,-1,5}];

Manipulate[
Graphics[{Hue[hue],Disk[]}]
,{hue,0,1}];

Manipulate[

Show[Graphics[{Hue[hue],Disk[{0,0},r]}],PlotRange->{{-1,1},{-1,1}}]

,{hue,0,1}
,{r,0,1}];

mat[fi_]:=(({{Sin[fi], Cos[fi]}, {Cos[fi], -Sin[fi]}}));
point[fi_]:=Graphics[{PointSize[Large],Pink,Point[{1,1}.mat[fi]]}];
Manipulate[
Show[point[fi],PlotRange->{{-2,2},{-2,2}}]
,{fi,0,2Pi}
]

(* 15.3.18 *)

ClearAll["Global`*"]

SeedRandom[1]
data=Table[{t,(Sqrt[2])231Sin[314t]+Random[Real,{-60,60}]},{t,0,0.08,0.001}];
ListPlot[data];

sourceBadSin=Interpolation[data];

R=1;
L=1*(10^(-3));
Cap=10*(10^(-6));
(*V=(Sqrt[2])*231*Tanh[1000*Sin[314*t]];*)
V=sourceBadSin[t];

Eqn={IR[t]==IL[t],IL[t]==IC[t],V==V3[t],((V3[t]-V2[t])/R)==IR[t],V2[t]-V1[t]==L*D[IL[t],t],IC[t]==Cap*V1'[t],IL[0]==0,V1[0]==0}

TreeForm[Eqn];

Var=Union[Cases[Eqn,_Symbol[t],{1,Infinity}]];

Sol=NDSolve[Eqn,Var,{t,0,0.04},StartingStepSize->(10^(-20))];
Plot[{V,10*IC[t]/.Sol},{t,0,0.04}]

Manipulate[Plot[Tanh[k*Sin[314t]],{t,0,0.06}],{k,1,100}]

(*22.3.2018*)
ClearAll["Global`*"]

(*29.3.2018*)
ClearAll["Global`*"];
expr[x_]:=a*(x^2)+b*x+c;
equations={expr[x0-Δx]==fMinus,expr[x0+Δx]==fPlus,expr[x0]==f0};
solabc=Solve[equations,{a,b,c}][[1]];
integrand=expr[x]/.solabc;
integral=Integrate[integrand,{x,x0-Δx,x0+Δx}]//Simplify

f[x_]:=10-0.1Exp[0.2x];
Plot[f[x],{x,0,20}];
{xmin,xmax}={0,20};
(*Print["exact integral=",Integrate[f[x],{x,xmin,xmax}]]*)
nValues=17;
Δx=((xmax-xmin)/(nValues-1))//N;
values=Range[xmin,xmax,Δx];
Length[%]==nValues;
Partition[{a,b,c,d,e,g,h,i},3,2];
partitionedValues=Partition[values,3,2];
weigths={1,4,1};
((Δx)/3)Plus@@(#.weigths&/@partitionedValues)

f[x_]:=10-0.1Exp[0.2x];
Plot[f[x],{x,0,20}];
{xmin,xmax}={0,20};
(*Print["exact integral=",Integrate[f[x],{x,xmin,xmax}]]*)
nValues=7;
Δx=((xmax-xmin)/(nValues-1))//N;
values=f/@Range[xmin,xmax,Δx];
Length[%]==nValues;
partitionedValues=Partition[values,3,2];
weigths={1,4,1};
((Δx)/3)Plus@@((#.weigths&)/@partitionedValues)

partitionedValues

Integrate[f[x],{x,xmin,xmax}]