Solve

Przyklady uzycia Solve

Solve[x^2==1,x]

x^2==1/.%

Solve[x^2==a,x]

Solve[a x^2+b x+ c==0,x]

eqn=a x^2+b x+c ==0

Solve[eqn,x]
eqn/.%
Simplify[%]

eqn=Total[(Subscript[a, #]) x^#&/@Range[0,5]]==0

Solve[eqn,x]

sol=Solve[eqn,x]
eqn/.%
%//Simplify

eqn[[1]]^2+1//Expand
%/.sol//Simplify

Solve[eqn/.(Subscript[a, n_]):>n+1,x]
%//N

r1=Root[1+2#+3#^2+4#^3&,1]
%^2+%
%//FullSimplify

ContourPlot[{x^2+y^2==1,x^2-y^2==1/2},{x,-2,2},{y,-2,2}]

sol=Solve[{x^2+y^2==1,x^2-y^2==1/2},{x,y}]

Jak otrzymac pary punktow?

sol[[1]]
sol[[1,2]]
sol[[1,2,2]]
sol[[1,All,2]]
sol[[All,All,2]]

ContourPlot[{x^2+y^2==1,x^2-y^2==1/2},{x,-2,2},{y,-2,2},Epilog->(Point/@sol[[All,All,2]])]

Problemy z Solve

Solve[Sin[x]==1/2,x]
Plot[{Sin[x],1/2},{x,-2Pi,2Pi},Epilog->Point[{Pi/6,1/2}]]

Rownania transcendentne

Solve[Sin[x]+x==0,x]

sol=Solve[Sin[x]+x==0,x];
If[Head[sol]===Solve,
Print["Error"]
]

Problemy z rownaniami z parametrem

Solve[Abs[z]==a,z]

Abs[z]==a/.%//Simplify

Solve[Sqrt[z^2]==a,z]

Solve[{x==a,a==2x},x]

Solve[x^n==1,x]

Reduce[x^n==1&&Abs[x]==1&&Im[n]==0,x]

Eliminate, SolveAlways

Solve[{x==a^2+1,Sin[a]==2y},x]

Solve[{x==a^2+1,Sin[a]==2y},x,a]

Eliminate[{x==a^2+1,Sin[a]==2y},a]

Eliminate[{x==a,a==2y},a]

Solve[Eliminate[{x==a,a==2y},a],x]
Solve[{x==a,a==2y},x,a]

SolveAlways[a x+b==0,x]

eqn=a x^2+b x+c==0
Solve[!Eliminate[!eqn,x]]

!eqn
Eliminate[%,x]
!%//Simplify
Solve[%]

LinearSolve

MatrixForm[A=RandomInteger[1,{10,10}]+IdentityMatrix[10]]
MatrixForm[b=RandomInteger[1,{10}]]

A.x == b

LinearSolve[A,b]

Reduce

Solve[Abs[z]==a,z]

Reduce[Abs[z]==a,z]

Domyslnie Reduce (jak cala Mathematica) pracuje na liczbach zespolonych

Reduce[Abs[z]==a,z,Reals(*zawezenie dziedziny zmiennych*)]

Reduce[x^2+y^2==10&&x^2-y^2==1/2,{x,y},Reals]
%//N

Reduce[x^2+y^2==10,{x,y},Integers]

Solve[Sqrt[z^2]==a,z]

Reduce[Sqrt[z^2]==a,z,Reals]

Reduce[Cos[x]==1,x]

Reduce[Cos[x]==Sin[x],x]

Reduce[Cos[x]==Sin[x],x,Reals,GeneratedParameters->((Subscript[A, #])&)]

Reduce[Cos[x]==Sin[x],x,Reals,GeneratedParameters->(n&)]

Reduce[Cos[x]==Sin[x],x,Reals,GeneratedParameters->(n&)]//FullSimplify

ToRules

Reduce[x^2+y^2==10,{x,y},Integers]

ToRules[%]

List[%]

List[ToRules[Reduce[x^2+y^2==10,{x,y},Integers]]]

List[ToRules[Reduce[x^2+y^2==10,{x,y},Integers]]][[All,All,2]]

{x,y}/.List[ToRules[Reduce[x^2+y^2==10,{x,y},Integers]]]

ToRules nie radzi sobie we wszystkich przypadkach!

List[ToRules[Reduce[Cos[x]==Sin[x],x,Reals,GeneratedParameters->(n&)]//FullSimplify]]

Zawezenie dziedziny Reduce

Reduce[Cos[x]==Sin[x],x,Reals,GeneratedParameters->(n&)]//FullSimplify

Reduce[Cos[x]==Sin[x] && Abs[x]≤10,x,Reals,GeneratedParameters->(n&)]//FullSimplify

List[ToRules[Reduce[Cos[x]==Sin[x]&&Abs[x]≤10,x,Reals,GeneratedParameters->(n&)]//FullSimplify]]

Solve[Reduce[Cos[x]==Sin[x] && Abs[x]≤10,x,Reals,GeneratedParameters->(n&)]//FullSimplify,x]

NSolve i FindRoot

NSolve

NSolve[eqn, x] daje ten sam wynik co N[Solve[eqn, x]] (jesli Solve sobie nie poradzil, NSolve tez polegnie)

NSolve[eqn/.a[n_]:>n+1,x]

Te same problemy co w przypadku Solve

NSolve[Sin[x]==1/2,x]

NSolve[Sin[x]+x==0,x]

N[Solve[...]]

FindRoot

FindRoot - znajduje tylko jedno rozwiazanie na raz, ale mozna kontrolowac precyzje rozwiazania i algorytm

f[x_]:=Cos[10x]
g[x_]:=-x

FindRoot[f[x]==g[x],{x,1}]

Plot[{f[x],g[x]},{x,-2,2}]

roots=FindRoot[f[x]==g[x],{x,#}]&/@Range[-1,1,.1]

TableForm[InputForm/@roots[[All,1,2]]]

roots[[All,1,2]]
Round[%,1*^-10]
Union[%]
N[%]

rootsSorted=Union[Round[roots[[All,1,2]],1*^-10]]//N

Plot[{f[x],g[x]},{x,-2,2},Epilog->(Point[{#,f[#]}]&/@rootsSorted)]

FindRoot[x^2==1-x,{x,10},EvaluationMonitor:>Print[x]]

SortRoots[r_,ϵ_]:=Union[Round[r,ϵ]]//N

fr[f_,s_]:=FindRoot[f[x],{x,s},PrecisionGoal->11,MaxIterations->20][[1,2]]
frInRange[f_,rng_,ϵ_]:=Module[{r=fr[f,#]&/@Range@@rng},
SortRoots[DeleteCases[r,FindRoot],ϵ]
]

frInRange[#&,{-2,2,.1},1*^-10]

ListPlot[Flatten[Table[{#,a}&/@frInRange[f[#]-a g[#]&,{-2,2,.1/Pi},1*^-10],{a,0,10,.01}],1],PlotRange->{{-2,2},All}]

Problemy z FindRoot

Manipulate[
Plot[{f[x],a g[x]},{x,-2,2},Epilog->(Point[{#,f[#]}]&/@frInRange[f[#]-a g[#]&,{-2,2,.1},1*^-10])],
{a,0,1}]

Manipulate[