Quiet@Remove["Global`*"];
$HistoryLength=2;
SetDirectory[NotebookDirectory[]];

?=

vyraz=x+y+Sin[(x^2)+2*y*x+3];
TreeForm[vyraz]

vyraz=x+y+Sin[(x^2)+2*y*x+3];
FullForm[vyraz]

Head[vyraz]

TreeForm[x*y]

x*y=5

x+y=5

Attributes[Plus]

(*o listech*)
listik={1,{2,3},{0,{alfa,romeo}}};
TreeForm[listik];

listik[[0]]

listik[[-1,2,-1]]

listik[[-1,2,-1]]=diCaprio

listik

Part[listik,-1]

(*volani funkci*)
{Sin[x],Sin@x,x//Sin}

listik={1,{2,3},{0,{alfa,romeo}}};
Length[listik];
Last[listik]
First[listik]

TreeForm[listik];

vyraz=x+y+Sin[(x^2)+2*y*x+3];
TreeForm[vyraz]

vyraz[[3,1,2,2]]

(*pravidla*)
(x^2)/.x->2

Rule[x,2]

ReplaceAll[(x^2),x->2]

ReplaceAll[Power[x,2],Rule[x,2]]

(x^2)+y/.{x->E+y,y->Pi+x,x->(Sqrt[2])}

(1/(I*ω*c))/.{c->10nF,nF->(10^(-9))}

?//.

(1/(I*ω*c))//.{c->10nF,nF->(10^(-9))}(*rekurze*)

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

(x^2)/.{{x->2},{x->3},{x->4}}

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

(*Equal, rovnice*)
Equal[lhs,rhs]
{1==1,1==2,Equal[1,1],Equal[1,2]}

(*pouziti pro praci s koreny rovnic*)
Quiet@Remove["Global`*"];
rce=(x^3)+(2+I)*(x^2)+2I*x+14.==0;
lhs=rce[[1]];
dosadZaIkska=Solve[rce]
x1=x/.dosadZaIkska[[1]];
x2=x/.dosadZaIkska[[2]];
vysledek=x1+2*x2;
Print["x1+2*x2= ",vysledek]

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

(x/.dosadZaIkska).{1,2,0}
Dot[(x/.dosadZaIkska),{1,2,0}]

Range[100]/.List->Plus

N[Range[100]/.List->Times]

expr=y-x/.{{x->2},{x->3},{x->4}};
rce=Expand[(0==expr/.List->Times)/.y->x];
reseni=Solve[rce]

reseni[[1]]

x1=reseni[[1,1,2]]
TreeForm[x1];

x1=x/.reseni[[1]]

(*patterny*)
?_

?__

?___

vyraz=Sin[(x^2)+3]+(x^y)+(E^Pi)

vyraz/.((a_)^(b_)):>(b^a)

vyraz/.(x^(b_)):>(b^x)

vyraz/.((a_)^(b_))->(b^a)
vyraz/.((a_)^(b_)):>(b^a)

Rule[a,b]

RuleDelayed[a,b]

?Rule

(*zde zacina druhy prednes*)
Quiet@Remove["Global`*"];
(*jeste trochu o Rules*)
?RuleDelayed

vyraz=Sin[(x^2)+3]+(x^y)+(E^Pi)
a=5;
vyraz/.((a_)^(b_)):>(b^a)
vyraz/.((a_)^(b_))->(b^a)

(*funkce*)
ClearAll[f];
(*dvojtecka pojmenovava pattern*)
f[x:_]:=(x^2)
f[2]

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

?:=

ClearAll[f];
f[x_]:=1+1

?=

ClearAll[f];
f[x_]=1+1
?f

rn:=Random[]
{rn,rn,rn,rn}
?rn

rn=Random[]
{rn,rn,rn,rn}
?rn

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

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

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

(*kdy je treba :=*)
ClearAll[f];
f[x_]:=FindRoot[Cos[a*x]==a,{a,0}]
f[0.5]

ClearAll[f];
f[x_]=FindRoot[Cos[a*x]==a,{a,0}]
f[0.5]

(*www.mathworld.com*)

(*kdy je treba =*)
f[x_]=Integrate[(Sqrt[x])*Sin[x],x]
f[0.1]
?f

(Sqrt[x])*Sin[x]/.x->0.1

(*kdy je treba =*)
f[x_]:=Integrate[(Sqrt[x])*Sin[x],x]
f[0.1]

(1/0)

Log[-0.13]

(*pretezovani funkci*)
ClearAll[f];
f[x_]:=(x^2);
f[0]:=100;
f[x_Integer]:=(1/x);
{f[3.],f[0],f[3]}

ClearAll[f,test];
test[y_]:=y≤3;
f[x_?test]:=x;
f[x_]:=9;
Plot[f[x],{x,0,5}];

(*sledovani vycisleni fce*)
ClearAll[a];
a[n_Integer]:=n*a[n-1];
a[0]:=1;
Trace[a[3]]

Table[opice,{12}];

Table[(i^2),{i,10}];

Table[(i^2),{i,3,10}];

Table[(i^2),{i,3,10,0.3}]

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

$RecursionLimit=(10^5);
ClearAll[a];
a[n_Integer]:=a[n]=n*a[n-1];
a[0]:=1;
a[6]
Trace[a[7]]
?a

$RecursionLimit=(10^5);
ClearAll[a];
a[n_Integer]:=a[n]=n*a[n-1];
a[0]:=1;
Timing[Table[a[i],{i,10000}]][[1]]

Quiet@Remove["Global`*"];
?/;

ClearAll[f];
f[x_]:=x/;x≤3;
f[x_]:=9/;x>3;
Plot[f[x],{x,0,5}];

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

(*existuje nekolik dalsich zpusobu*)
?Which

?Piecewise

(*jine formaty parametru*)
ClearAll[a];
a[{x_,y_}]:=x+y;
a[{Pi,2E}]

https://chat.openai.com/chat

Ahoj, mohla bys prosím napsat skript ve Wolfram Mathematica, který vygeneruje graf funkcí Sin a Cos, sinus modře kosínus červeně, popíše osy a graf bude mít GridLines?

Plot[{Sin[x],Cos[x]},{x,-2Pi,2Pi},PlotStyle->{{Blue,Thickness[0.007]},{Red,Thickness[0.007]}},AxesLabel->{"x","y"},PlotLabel->"Graf Sin a Cos",GridLines->Automatic,GridLinesStyle->Directive[Gray,Dashed],ImageSize->Large]

AI: Tento skript vykreslí Sinus modře a kosinus červeně na intervalu <-2π, 2π>. Osa x je popsaná jako “x” a osa y jako “y”. Graf má název “Graf Sin a Cos” a obsahuje mřížky pomocí volání GridLines -> Automatic a GridLinesStyle -> Directive[Gray, Dashed]. Velikost grafu je určena voláním ImageSize -> Large.


já: Super, děkuji!

AI:-)
Ráda jsem pomohla! Pokud budete mít další dotazy nebo požadavky ohledně Wolfram Mathematica nebo jiných věcí, neváhejte se na mě obrátit.

(*ukazat Eulerovu metodu reseni ODE, ale predtim Module, Pure Functions (priklad se Select) a interpolace*)
Quiet@Remove["Global`*"];
s[a_]:=NDSolve[{y'[x]==y[x]Cos[x+a*y[x]],y[0]==1},y,{x,0,30}]
g[a_]:=Plot[Evaluate[y[x]/.s[a]],{x,0,30},PlotRange->All]
g[1]

Quiet@Remove["Global`*"];
f[a_]:=Module[{reseni},
reseni=NDSolve[{y'[x]==y[x]Cos[x+a*y[x]],y[0]==1},y,{x,0,30}];
Plot[Evaluate[y[x]/.reseni],{x,0,30},PlotRange->All]
];
f[2];

Quiet@Remove["Global`*"];
prechod[odkud_,kam_,kdeZmena_,strmost_,promenna_]:=Module[{rce,a,b,dosadab},
rce={a-b==odkud,a+b==kam};
dosadab=Solve[rce,{a,b}][[1]];
a+b*Tanh[strmost*(promenna-kdeZmena)]/.dosadab
];
pom=prechod[2,3,4,15,x]
Plot[pom,{x,0,8},AxesOrigin->{0,0}];

(*Pure Functions*)
f[x_]:=(x^2);(*pojmenovana funkce*)
f[5]

((#)^2)&[5]

(*# je Protected*)
#=5

g[x_,y_]:=x+(y^2)
g[E,Pi]

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

h:=#1+((#2)^2)&;
h[E,Pi]

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

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

#>2&[1]

Quiet@Remove["Global`*"];
test[x_]:=x>2;
f[x_?test]:=x;
f[x_]:=(x^2)-2;
Plot[f[x],{x,0,4}]

Quiet@Remove["Global`*"];
(*& ma vlekou prioritu, zavorky casto nutne*)
f[x_?(#>2&)]:=x;
f[x_]:=(x^2)-2;
Plot[f[x],{x,0,4}];

Quiet@Remove["Global`*"];
(*Map a Apply*)
Map[f,{1,2,3,4}]
f/@{1,2,3,4}

(*Mapovani neni nutne u finkci, ktere maji Attribut Listable*)
Sin[{1,2,3,4}]
Sin/@{1,2,3,4}
Attributes[Sin]

Quiet@Remove["Global`*"];
(*Map a Apply*)
Apply[f,{1,2,3,4}]
f@@{1,2,3,4}

{TreeForm[{1,2,3,4}],TreeForm[f@@{1,2,3,4}]}

mat=Table[RandomInteger[{-5,5}],{i,3},{j,3}]
MatrixForm[mat]

mat/.List->Plus

Plus@@mat

Range[10]

Plus@@(((#)^3)&/@Range[10])

(∑_(i=1)^10)(i^3)

Attributes[Pi]

Head[Pi]

Plot[#[x],{x,0,2Pi}]&/@{Sin,Cos,((#)^2)&}

NumberQ[Pi]

NumericQ[Pi]

N[Pi,#]&/@Range[5,20,1]

Nest[f,x,5]

NestList[f,x,5]

(*Eulerova metoda*)
Quiet@Remove["Global`*"];
derivace[{t_,y_}]:=-2y;
pocBod={t0,y0}={0.,10};
tmax=2;
nKroku=100;
Δt=((tmax-t0)/nKroku);
krokEuler[bod:{t_,y_}]:={t+Δt,y+Δt*derivace[bod]};
reseni=NestList[krokEuler,pocBod,nKroku];
plEuler=ListPlot[reseni,AxesLabel->{"t","y"},PlotStyle->{PointSize[0.005],Red},GridLines->Full];
rceNDSolve={y'[t]==derivace[{t,y[t]}],y[t0]==y0};
solNDS=NDSolve[rceNDSolve,y,{t,t0,tmax}][[1]];
plNDS=Plot[y[t]/.solNDS,{t,t0,tmax}];
Show[plEuler,plNDS]