Sunteți pe pagina 1din 5

Solving Non-linear Equation

A. Non linear equations



Many problems in chemical engineering require solution of non-linear equation(s). Example:
Non ideal gas equation of state (SRK): P=R*T/(V-b) a*/(V*(V+b))
Friction factor for turbulent flow in a pipe:

0.86 log

.

.


Dll

B. Solving Nonlinear Equations

The theory and algorithms for solving a nonlinear system of equations
fct(x)=0 (1)

Assuming that f is differentiable, the primary Scilab utility is fsolve. It has the calling sequence

[x [,v [,info]]]=fsolve(x0,fct [,fjac] [,tol])

and uses the Powell hybrid method.

The simplest calls need only:
x0: Real vector that is the initial value of the function argument.
fct: External providing function in (1)

The optional parameters are:
fjac: External providing the Jacobian of fct.
tol: Real scalar, which is a precision tolerance. Termination occurs when the algorithm
estimates that the relative error between x and the solution is at most tol. Default value
is tol=1.d-10.
x: Final value of function argument. Estimated solution of (4.7).
v: Value of function fct at x. Should be close to zero if a solution has been found.
info: Indicates why termination occurred.
0: improper input parameters.
1: algorithm estimates that the relative error between x and the solution is at
most tol.
2: number of allowed calls to fct reached.
3: tol is too small. No further improvement in the approximate solution x is
possible.
4: iteration is not making good progress.

The simplest calling sequence for fct is [v]=fct(x).

EXAMPLE 1. Solve the following simultaneous linear equations:
x + y = 7
x^2*y + 6*(y/x) = 35

fsolve try to find a x* such that f(x*) = 0, (precisely an approximation of such an x*) where f is a
function which takes on entry a real vector with n component and outputs a real vector with n
components (so that the 0 on the right is [0;0;....;0]). For the problem, one can use :

function Z=myequ(X)
x = X(1);
y = X(2);
Z(1) = x + y - 7;
Z(2) = x^2*y + 6*y/x - 35;
endfunction

Then fsolve may give you a solution. Starting from X0=[1;1] i get :

-->z = fsolve([1;1],myequ)
z =
1.3969091
5.6030909

A closer look shows that there are 4 solution points to your system. So different starting points
could lead to other solution than (1.3969091,5.6030909 ) for instance :

-->z = fsolve([1.9;5.7],myequ)
z =
2.
5.


Tugas 03
Problem 1.


Problem 2.

S-ar putea să vă placă și