Nastaveni defaultniho adresare usetri dost casu... a kazdy v Mathematice pripustny objekt si muzeme schovat o priponu a reprezentaci v pameti se nestarajice...

SetDirectory[NotebookDirectory[]]

Directory[]

?Put

pl1=Plot[Im[(E^(I*Sin[x]))],{x,0,10}]>>"obr"

InputForm[pl1];

<<"obr"

FileNames[]

SetDirectory[NotebookDirectory[]]
Integrate[Sin[I*x]*Exp[x],x]>>"int";

FileNames[]

int[x_]=<<"int"
int[I*(Pi/4)]

FullForm[I (((E^(2 x))/4)-(x/2))]

DeleteFile["int"]
FileNames[]

(Sqrt[7])+(Sqrt[18])

(Sqrt[7])//FullForm

Attributes[Power]

(Sqrt[7])=2

Unprotect[Power]

(Sqrt[7])=2

(Sqrt[7])

(Sqrt[6])

??Power

?a

a*8

Pi//Sin

Mathematice casto staci rict presne, co vlastne chceme a ona to udela...

ClearAll[Power]

?=

ClearAll[int,x];
int[x_]=<<"int"
int[1.]

?int

?:=

?FindRoot

?/.

FindRoot[Cos[x]==x,{x,0}]

NestList[Cos,x,50];

ClearAll[a];
res[a_]:=x/.FindRoot[Cos[a*x]==x,{x,0}]

?res

ClearAll[f];
f[x]=5;
f[y]=10;
f[x]-f[y]

y=5

ClearAll[f];
f[10]=5;
f[x]=2;
f[x_]=3;
f[y]=6;

?f

f[r]
f[10]
f[x]

fce[a_]:=5+a

fce

res[w]

pravidlo=b->5

b/.pravidlo

b->5//FullForm

ClearAll[a];
a[n_]:=n*a[n-1];
a[0]:=1;

a[6]==6!

Trace[a[3]]

?a

nmax=(10^3);
$RecursionLimit=Max[256,nmax+5]

Print["pro vypocet 0 az ",nmax," to trvalo ",pom=Timing[a/@Range[nmax]];pom[[1]]," s"]

Definice vyrazu se muze pri jeho pouzivani menit, napr. doplnovat...coz muze vyrazne zrychlit vypocty s vyuzitim optimalizace "pamet kontra algoritmus"

ClearAll[a];
a[n_]:=a[n]=n*a[n-1];
a[0]:=1;

a[6]
?a

Trace[a[8]]

nmax=(10^3);
Print["pro vypocet 0 az ",nmax," to trvalo ",pom=Timing[a/@Range[nmax]];pom[[1]]," s"]

ClearAll[a];
a[1]=1;
a[n_]:=a[n]=(1./2)*(a[n-1]+(2/(a[n-1])));
vysledky=Table[a[i],{i,100}];
a/@Range[100];

g/@Range[10]

Range[50,100,2]

ostrihej/@{ja,ty,on,ona}
Map[ostrihej,{ja,ty,on,ona}]

ListPlot[a/@Range[100]]

ClearAll[a];
a[1]=1;
a[n_]:=0.+(1/2)*(a[n-1]+(2/(a[n-1])));
a[5];

Trace[a[5]];

Funkce muze mit za parametr ledacos (kdo dokaze, aby to mohl byt Subscribe, ma u me pivko), vracet muze skoro cokoli...

ClearAll[f];
f[hue_]:=Graphics[{Hue[hue],Disk[{0,0},1,{Pi/4,3Pi/4}]}];
Manipulate[f[hue],{{hue,0.5,"hue"},0,1},ControlPlacement->Top];

ClearAll[f,a,i];
f[(Subscript[a, i])_]:=(Subscript[a, i])

(Subscript[a, i])//FullForm

a+b+c//FullForm
{a,b,c}//FullForm

Plus@@List[a,b,c]

Apply[Plus,{a,b,c}]

listik={ja,{alfa,{romeo,1}},{1,2,{8}}};
listik[[-1,-1,1]]

vyr[[1]]

vyr=I (((E^(2 x))/4)-(x/2));
%//TreeForm

kyncl je vul//TreeForm

vyr[[1]]//TreeForm

Cos@@Sin[(Sqrt[2])]

ClearAll[fce]
fce@@{{a,b},c}
{{a,b},c}/.List->fce

SetAttributes[exp,{HoldAll,Listable}];
exp[co_]:=Module[{a,graf},a=ToString[Unevaluated[co]];graf:=Evaluate[co];Export[Evaluate[a<>".png"],graf,ImageResolution->300]];

plsin=Plot[Sin[x],{x,0,2Pi}]
exp[plsin]

Zasahy cloveka jsou nezadouci; to co pozaduje nejaky prikaz jako parametr, muzeme casto stvorit automaticky... ukazeme si to na Cases a FindFit....

SeedRandom[10042];
xBord=1;
dat={#,1+2#+3((#)^2)*Sin[5#]+Random[Real,{-0.2,0.2}]}&/@Range[-xBord,xBord,0.1];
pl1=ListPlot[dat,AxesLabel->{"x","f [x]"},PlotStyle->{PointSize[0.015],Magenta}];
v:=(Subscript[α, #])&;
model=v[1]+v[2]*x+v[3]*(x^2)*Sin[v[4]*x];
params:=Union@Cases[#,(Subscript[α, _]),{0,∞}]&;
vys=model/.FindFit[dat,model,params[model],x];
pl2=Plot[vys,{x,-xBord,xBord},AxesLabel->{"x","f [x]"},PlotStyle->{Thickness[0.006],Black}];
Show[pl1,pl2]

...jelikoz je to dulezite, ukazeme si to jeste jednou. V elektrickych obvodech casto bereme pocatecni podminky ve forme nulovych proudu a napeti. Pro nejaky takovy obvod si ukazeme, jak optimalizovat programovani same (...vypocetni cas zpravidla mensi jest, nez doba programovani, je tedy treba optimalizovat oboje. Jiste, program bezi vicekrat, ergo doba behu ma roli opakujicich se nakladu a doba programovani roli zvahovanych investic... nebo neco v tom smyslu:-))
Ukazka pro "mirne pokrocile" samosebou neni optimalni. Celkem snadno lze pri prijeti umluv, jak budu znacit nezname a zdroje atd., napsat solver, ktery si jen vezme rovnice a pak sam udela o neco optimalneji to, co my ukazujeme. Ponechavame ctenari coby cviceni:-)

uz=1+0.5*Sin[5t+0.4];
μF=(10^(-6));
k=1000;
R=10k;
c=5μF;
L=0.1;
rce={uz==R*i[t]+uc[t]+L*i'[t],i[t]==c*uc'[t]};
(*nezname=Cases[rce,_[t],{0,∞}]*)

rce

Head[kyncl]

nezname=Union@Cases[rce,_Symbol[t],{0,∞}]

derNezn=Union[Cases[rce,_'[t],{0,∞}]]

x=5

pocs=derNezn/.x_'[t]:>x[0]==0

tmax=2;
ki=(10^4);
res=NDSolve[Union[rce,pocs],nezname,{t,0,tmax}][[1]];
Plot[Evaluate[nezname*{ki,1}/.res],{t,0,tmax},AxesLabel->{"t [s]",ToString[nezname*{ki,1}]},PlotStyle->Thick]

(*mirne pokrocilejsi zapis tehoz...*)
vydej:=Union@Cases[rce,#,{0,∞}]&;
nezname=vydej[_Symbol[t]]
pocs=vydej[_'[t]]/.x_'[t]:>x[0]==0
(*... da capo al fine...*)

Praci s "formaty promennych" si ukazeme na Eulerove evolucni metode... a to jak na formatu parametru funkci, tak na formatu mezivypoctu...

poc={0,1};
tmax=3;
n=2400;
Δt=(tmax/n);
dery[{t_,y_}]:=((-1)/10)t+y;
EuStep[p:{t_,y_}]:={t+Δt,y+dery[p]*Δt};
pom=Timing[NestList[EuStep,poc,n]];
Print["trvalo to: ",pom[[1]]," s"]
ListPlot[pom[[2]],AxesLabel->{"x","y [x]"}];

poc={0,1.};
tmax=3;
n=2400;
Δt=(tmax/n);
dery[{t_,y_}]:=((-1)/10)t+y;
EuStep[p:{t_,y_}]:={t+Δt,y+dery[p]*Δt};
pom=Timing[NestList[EuStep,poc,n]];
Print["trvalo to: ",pom[[1]]," s"]
ListPlot[pom[[2]],AxesLabel->{"x","y [x]"}];

...pochopili? Urcite pochopili! :-)
...pro Mathematicu neni zavazny postup vyuky na FEL, obcas se hodi pouzit "neco pozdeji" na "neco drive", ukazme si to na prikladu integral kontra reseni dif. dovnice...

ClearAll[fce];
SeedRandom[1];
tmax=3;
fce=Interpolation[{#,#+Random[]}&/@Range[0,tmax,(tmax/500)]];
int1=NIntegrate[fce[x],{x,0,tmax}]

ClearAll[fce];
SeedRandom[1];
tmax=3;
fce=Interpolation[{#,#+Random[]}&/@Range[0,tmax,(tmax/500)]];
myInt=(y/.NDSolve[{y'[t]==fce[t],y[0]==0},y,{t,0,tmax},MaxSteps->(10^8),MaxStepSize->(tmax/(10^5))][[1]])[tmax]

?Riffle

?? @
  ρ
  "esc rho esc"
  
  Sequence @@
   %1
  %%%
  packages
  module