Solving NLEs
to solve Non-linear Equation system:
Let's solve following equation system:
First create block with equations. Start with block(name) command, where "name" is identifier of the block:
block(b1)
All equations should be rewritten in form f(x) = 0, i.e everything should be moved to the left side of the equation. Then you define left side only:
x^2 + y^2 + z^2 - 1
2*x^2 + y^2 - 4*z
3*x^2 - 4*y + z^2
After block is finished type:
end
Equations are solved numerically by using Newtons method, so the initial assumptions for root values should be passed to the solver. Create a vector with initial assumptions:
X0 = < .5, .5, .5 >
And finally solve the system by using solve() function. First pass the name of the equation block (in our case: b1), then pass vector with initial assumptions (X0), and then list all output variables to search for:
X = solve(b1, X0, x, y, z)
now X is a vector containing all calculated roots in the same order: x, y, z. You can use explode() command to create output variables from equation block and result vector. Execute:
explode(b1, X)
This will automatically create three variables x, y, z, which values will be equal to equation roots (Careful! These variables will overwrite existing ones if they exist).
To edit equation in the block one can use edit command:
edit b1 1: x^2 + y^2 + 2*z^2 - 5
- where you should type block identifier, target row number (starts from 1), and then your equation after colon.