



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
This tutorial helps you use MATLAB to solve nonlinear algebraic equations of single or multiple variables. 2 Writing MATLAB functions. In order to use the ...
Typology: Study notes
1 / 5
This page cannot be seen from the preview
Don't miss anything!
This tutorial helps you use MATLAB to solve nonlinear algebraic equations of single ormultiple variables.
In order to use the MATLAB solvers, you must first be able to write MATLAB functions.There are two different methods to create a function - (a) inline command, and (b) Matlab editor
The inline command can be used for simple, one-line functions. For example, to create f ( x ) = x (^3) - 5 x (^2) -x + 2 :
>> f = inline (‘ x^ 3 -5x^2 - x + 2’) _f = Inline function: f(x) = x^3-5x^2-x+_ You can now evaluate the function value at any given x. For example, to evaluate the function value at x = 4, simply type ‘ f (4)’ at Matlab command line. EDU>> f(4) ans =
-
The editor allows the user to write functions of any length and/or complexity.
The following command solves the equationinitial guess of x = 4. y = f ( x ) = x^3 - 5 x^2 -x + 2 ;, starting from an
EDU>> fzero(f,4) MATLAB returns the answer: ans = 5. Changing the initial guess to x = 2 EDU>> fzero(f,2) gives ans =
NOTE: In utilizing ROOTS function, all coefficients of the polynomial must bespecified.
e.g. f ( x ) = x^4 - 3 x^2 + 2. The function in the full polynomial form must be expressed as: f ( x ) = 1w x^4 - 0wx^3 +3w x^2 -0 w x + 2. Accordingly, the polynomial must be defined in MATLAB as follows: p = [1 0 -3 0 2]:
5 FSOLVE The MATLAB routine fsolve is used to solve sets of nonlinear algebraic equations usinga quasi-Newton method. The user must supply a routine to evaluate the function vector. Consider the following system of nonlinear equations, and solve for x 1 and x 2 :
The m-file used to solve the above problem using fsolve is:
which is placed in a m-file called nle.m. Enter the initial guess
Note: x (^) o is the TRANSPOSE of a row vector Now, solve with x = fsolve ( ‘ nle’ ; x 0 )
which gives us the results x = [0_._ 25 0_._ 00] ’.