Professional Documents
Culture Documents
Fifth Lecture
Fifth Lecture
(column) vector x as
Ax = b,
or, componentwise, as
1
x=A b,
32
Then we can find the solution of the linear system of equations as
x = inv( A) ⇤ b.
The last command produces the expected result; that is, the result of the inversion
x = linsolve( A, b).
Example
Write a Matlab code to find the solution of the following system of linear equations:
x + 2y = 4
3x + 4y = 5.
Solution:
A = [1 2 ; 3 4];
b = [4 ; 5];
In order to use the Matlab solvers, you must first be able to write Matlab functions.
1. Anonymous Function.
33
2. Matlab Editor. (we have disscused this type in the first semester)
functions can accept multiple inputs and return one output. They can contain
For example, create a handle to an anonymous function that finds the square
of a number:
>> sqr = @( x ) x. ˆ 2;
fzero can be used to solve a single variable nonlinear equation of the form
function or m-file).
>> f = @( x ) x ˆ 3 5x ˆ 2 x + 2;
>> f zero ( f , 4)
Example
Solution:
34
>> f = @( x ) cos( x ) x;
>> f zero ( f , 1)
ans= 0.7391
Example
Consider the following system of nonlinear equations, and solve for x1 and x2
x1 x2 5x2 + 10 = 0
Solution:
ans= 3 5
35