Mathematicaで方程式の解法

Solveコマンド

例題1. 方程式 f(x)=0 の解法

Solve[x^2 - 3*x - 4 == 0, x]

x /. Solve[x^2 - 3*x - 4 == 0, x]

Clear[sol]

sol := Solve[x^2 - 3*x - 4 == 0, x]

x /. sol

F[x]  /.  x -> a

例題2. 連立一次方程式の解法

1.

Solve[{2*x + y - 2 == 0, x - y - 1 == 0}, {x, 
        y}]

{x, y} /. 
      Solve[{2*x + y - 2 == 0, x - y - 1 == 0}, {x, 
          y}]

2.

Solve[{x - 2*y + 3*z == 2, 2*x - 3*y + 4*z == 3, 
        3*x - 8*y + 13*z == 8}, {x, y, z}]

Clear[sol2]

sol2 := 
      Solve[{x - 2*y + 3*z == 2, 2*x - 3*y + 4*z == 3, 
          3*x - 8*y + 13*z == 8}, {x, y, z}]

sol2 /. z -> c

3.

Solve[{x - y - 2 == 0, x - y - 1 == 0}, {x, y}]

NSolveコマンド, FindRootコマンド

\(例題3 . \ log \((x + 2)\) - log\ x = 
      3  の解法\)

Plot[Log[x + 2] - Log[x] - 3, {x, 0.01, 3}]

FindRoot[Log[x + 2] - Log[x] - 3, {x, 0.5}]

NSolve[Log[x + 2] - Log[x] - 3, x]

問題

1.

Solve[(3*x - 6)/(x - 1) + x - 2 == 0, x]

Plot[(3*x - 6)/(x - 1) + x - 2, {x, -5, 3}, 
      PlotRange -> {-20, 20}]

2.

Solve[Sqrt[x - 1] - x + 3 == 0, x]

3.

NSolve[x^5 + 2*x^4 + 3*x^3 - 2*x^2 + 5*x - 5 == 0, x]

4.

Plot[E^(x^2) - 3*Sin[x], {x, 0, Pi/2}]

FindRoot[E^(x^2) - 3*Sin[x] == 0, {x, 0.5}]

FindRoot[E^(x^2) - 3*Sin[x] == 0, {x, 1}]

5.

Plot[x^10 - 2^x, {x, -1, 2}]

FindRoot[x^10 - 2^x == 0, {x, -1}]

FindRoot[x^10 - 2^x == 0, {x, 1}]

NSolve[x^10 - 2^x == 0, x]

Whileコマンド

While[条件,命令] => 条件が true の間、命令を繰り返す

a[1] := 1

a[n_] := a[n - 1] + 3

m[N_] := Module[{n = 1}, While[a[n] < N, n = n + 1]; n - 1]

If コマンド

If[条件,命令1,命令2] => 条件が true なら命令1を、命令2を実行する

M[k_] := If[a[k] < 50, k + 1, k]