Professional Documents
Culture Documents
Matlab Lecture 6
Matlab Lecture 6
Lecture 6
Introduction to MATLAB
1
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
SOLVING MULTI
VARIABLE NON-
LINEAR EQUATIONS
USING MATLAB
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Topics to be covered
Multi-Variable equations
Linear equations in multiple variable
Non linear equations in multiple variables - fsolve
Other numerical methods – Modified Newton Raphson method
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
• To get the solution of multi-variable, one must have enough number of equations i.e., equal to the number of variables.
These equations combined are known as system of equations.
• It is easier to get the solution if the equations are linear, one can simply get it by using analytical methods.
• In matlab, we solve system of linear eqauations by simply defining the coefficient matrices. An example is provided in the
next slide.
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
• To solve this system of equations, one has to define the equations in the form;
AX = B
• Where, A is a matrix of coefficients of x, y and z and B is a column vector of scalars on the right side of the
equations. X is a vector of variables x, y and z.
• One can get the solution of equations by finding the inverse of the coefficient matrix A and multiplying it with vector B.
X = A-1B
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Practice Problem
𝑥 −𝑦 =0
2𝑥 − 𝑥𝑧 − 𝑦 = 0
𝑥𝑦 − 3𝑧 = 0
• There are various numerical methods developed for solving system of non-linear equations. Some of these are listed below:
Fixed Point Iteration
Modified Newton Raphson Method
Conjugate Gradient Method
Broyden’s Method
• MATLAB has an inbuilt solver fsolve to deal with a system of non-linear equations in multiple variables.
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
• SYNTAX
z = fsolve(function, x0)
z = fsolve(function, x0, options)
• Its syntax is almost similar to the syntax of fzero function, but it takes inputs of different type.
• fzero takes single non-linear equation in one variable and single guess value and provides single solution which is nearest
to the guess value.
• In case of fsolve, the function is a column vector which takes different non linear equations in different rows in the
column vector,
• Similarly, x0 is also a column vector of same length as the length of function vector and takes same no. of initial guesses
as the no. of equations.
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Example Problem
Providing a system a non-linear equation in a function file
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Example Problem
Solving the problem in the command window
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
𝑓(𝑥0 )
𝑥1 = 𝑥0 −
𝑓′(𝑥0 )
Geometrically, (x1, 0) is the intersection of the x-axis and the tangent of the graph of f at (x0, f (x0)).
𝑓(𝑥𝑛 )
• The process is repeated as 𝑥𝑛+1 = 𝑥𝑛 − until a sufficiently accurate value is reached.
𝑓′(𝑥𝑛 )
where k = 1, 2, ………. n represents the iteration, x ∈ ℝ𝑛 , F is a vector function, and J(𝑥)−1 is the inverse of the
Jacobian matrix.
• This equation represents the procedure of Newton’s method for solving nonlinear algebraic systems. However,
instead of solving the equation f(x) = 0, we are now solving the system F(x) = 0.
Steps…
Step – 1: Let 𝑥 (0) = (𝑥 0
1, 𝑥
0
2, 𝑥 0
3, … … … … … … … … 𝑥
0
𝑛) be the given initial vector.
0 0
Step – 2: Calculate 𝐽 𝑥 𝑎𝑛𝑑 𝐹 𝑥 .
Step – 3: Once 𝑦 (0) is found, we can now proceed to finish the first iteration by solving for 𝑥 (1) .
Step – 5: Once we have calculated 𝑥 (1) , we repeat the process again, until 𝑥 (𝑘) converges to x.
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Example Problem
Providing a system a non-linear equation in a function file
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Example Problem
Program of modified Newton-Raphson method
Adarsh Jain (Department of Chemical Engineering) MNNIT Allahabad, Prayagraj
Practice Problem
• Solve the following nonlinear system
𝟏
𝟑𝒙𝟏 − 𝒄𝒐𝒔 𝒙𝟐 𝒙𝟑 − =𝟎
𝟐
𝒙𝟐𝟏 − 𝟖𝟏 𝒙𝟐 + 𝟎. 𝟏 𝟐
+ 𝒔𝒊𝒏 𝒙𝟑 + 𝟏. 𝟎𝟔 = 𝟎
𝟏𝟎𝝅 − 𝟑
𝒆−𝒙𝟏 𝒙𝟐 + 𝟐𝟎𝒙𝟑 + =𝟎
𝟑