SlideShare une entreprise Scribd logo
1  sur  6
Télécharger pour lire hors ligne
http://www.tutorialspoint.com/matlab/matlab_alg ebra.htm Copyright © tutorialspoint.com
MATLAB - ALGEBRA
So far, we have seenthat allthe examples work inMATLAB as wellas its GNU, alternatively called Octave. But
for solving basic algebraic equations, bothMATLAB and Octave are little different, so we willtry to cover
MATLAB and Octave inseparate sections.
We willalso discuss factorizing and simplificationof algebraic expressions.
Solving Basic Algebraic Equations in MATLAB
The solve command is used for solving algebraic equations. Inits simplest form, the solve functiontakes the
equationenclosed inquotes as anargument.
For example, let us solve for x inthe equationx-5 = 0
solve('x-5=0')
MATLAB willexecute the above statement and returnthe following result:
ans =
5
Youcanalso callthe solve functionas:
y = solve('x-5 = 0')
MATLAB willexecute the above statement and returnthe following result:
y =
5
Youmay evennot include the right hand side of the equation:
solve('x-5')
MATLAB willexecute the above statement and returnthe following result:
ans =
5
If the equationinvolves multiple symbols, thenMATLAB by default assumes that youare solving for x, however,
the solve command has another form:
solve(equation, variable)
where, youcanalso mentionthe variable.
For example, let us solve the equationv – u– 3t2 = 0, for v. Inthis case, we should write:
solve('v-u-3*t^2=0', 'v')
MATLAB willexecute the above statement and returnthe following result:
ans =
3*t^2 + u
Solving Basic Algebraic Equations in Octave
The roots command is used for solving algebraic equations inOctave and youcanwrite above examples as
follows:
For example, let us solve for x inthe equationx-5 = 0
roots([1, -5])
Octave willexecute the above statement and returnthe following result:
ans =
5
Youcanalso callthe solve functionas:
y = roots([1, -5])
Octave willexecute the above statement and returnthe following result:
y =
5
Solving Quadratic Equations in MATLAB
The solve command canalso solve higher order equations. It is oftenused to solve quadratic equations. The
functionreturns the roots of the equationinanarray.
The following example solves the quadratic equationx2 -7x +12 = 0. Create a script file and type the following
code:
eq = 'x^2 -7*x + 12 = 0';
s = solve(eq);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));
Whenyourunthe file, it displays the following result:
The first root is:
3
The second root is:
4
Solving Quadratic Equations in Octave
The following example solves the quadratic equationx2 -7x +12 = 0 inOctave. Create a script file and type the
following code:
s = roots([1, -7, 12]);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));
Whenyourunthe file, it displays the following result:
The first root is:
4
The second root is:
3
Solving Higher Order Equations in MATLAB
The solve command canalso solve higher order equations. For example, let us solve a cubic equationas (x-
3)2(x-7) = 0
solve('(x-3)^2*(x-7)=0')
MATLAB willexecute the above statement and returnthe following result:
ans =
3
3
7
Incase of higher order equations, roots are long containing many terms. Youcanget the numericalvalue of such
roots by converting themto double. The following example solves the fourthorder equationx4 − 7x3 + 3x2 − 5x
+ 9 = 0.
Create a script file and type the following code:
eq = 'x^4 - 7*x^3 + 3*x^2 - 5*x + 9 = 0';
s = solve(eq);
disp('The first root is: '), disp(s(1));
disp('The second root is: '), disp(s(2));
disp('The third root is: '), disp(s(3));
disp('The fourth root is: '), disp(s(4));
% converting the roots to double type
disp('Numeric value of first root'), disp(double(s(1)));
disp('Numeric value of second root'), disp(double(s(2)));
disp('Numeric value of third root'), disp(double(s(3)));
disp('Numeric value of fourth root'), disp(double(s(4)));
Whenyourunthe file, it returns the following result:
The first root is:
6.630396332390718431485053218985
The second root is:
1.0597804633025896291682772499885
The third root is:
- 0.34508839784665403032666523448675 - 1.0778362954630176596831109269793*i
The fourth root is:
- 0.34508839784665403032666523448675 + 1.0778362954630176596831109269793*i
Numeric value of first root
6.6304
Numeric value of second root
1.0598
Numeric value of third root
-0.3451 - 1.0778i
Numeric value of fourth root
-0.3451 + 1.0778i
Please note that the last two roots are complex numbers.
Solving Higher Order Equations in Octave
The following example solves the fourthorder equationx4 − 7x3 + 3x2 − 5x + 9 = 0.
Create a script file and type the following code:
v = [1, -7, 3, -5, 9];
s = roots(v);
% converting the roots to double type
disp('Numeric value of first root'), disp(double(s(1)));
disp('Numeric value of second root'), disp(double(s(2)));
disp('Numeric value of third root'), disp(double(s(3)));
disp('Numeric value of fourth root'), disp(double(s(4)));
Whenyourunthe file, it returns the following result:
Numeric value of first root
6.6304
Numeric value of second root
-0.34509 + 1.07784i
Numeric value of third root
-0.34509 - 1.07784i
Numeric value of fourth root
1.0598
Solving System of Equations in MATLAB
The solve command canalso be used to generate solutions of systems of equations involving more thanone
variables. Let us take up a simple example to demonstrate this use.
Let us solve the equations:
5x + 9y = 5
3x – 6y = 4
Create a script file and type the following code:
s = solve('5*x + 9*y = 5','3*x - 6*y = 4');
s.x
s.y
Whenyourunthe file, it displays the following result:
ans =
22/19
ans =
-5/57
Insame way, youcansolve larger linear systems. Consider the following set of equations:
x + 3y -2z = 5
3x + 5y + 6z = 7
2x + 4y + 3z = 8
Solving System of Equations in Octave
We have a little different approachto solve a systemof 'n' linear equations in'n' unknowns. Let us take up a simple
example to demonstrate this use.
Let us solve the equations:
5x + 9y = 5
3x – 6y = 4
Sucha systemof linear equations canbe writtenas the single matrix equationAx = b, where A is the coefficient
matrix, b is the columnvector containing the right-hand side of the linear equations and x is the columnvector
representing the solutionas showninthe below program:
Create a script file and type the following code:
A = [5, 9; 3, -6];
b = [5;4];
A  b
Whenyourunthe file, it displays the following result:
ans =
1.157895
-0.087719
Insame way, youcansolve larger linear systems as givenbelow:
x + 3y -2z = 5
3x + 5y + 6z = 7
2x + 4y + 3z = 8
Expanding and Collecting Equations in MATLAB
The expand and the collect command expands and collects anequationrespectively. The following example
demonstrates the concepts:
Whenyouwork withmany symbolic functions, youshould declare that your variables are symbolic.
Create a script file and type the following code:
syms x %symbolic variable x
syms y %symbolic variable x
% expanding equations
expand((x-5)*(x+9))
expand((x+2)*(x-3)*(x-5)*(x+7))
expand(sin(2*x))
expand(cos(x+y))
% collecting equations
collect(x^3 *(x-7))
collect(x^4*(x-3)*(x-5))
Whenyourunthe file, it displays the following result:
ans =
x^2 + 4*x - 45
ans =
x^4 + x^3 - 43*x^2 + 23*x + 210
ans =
2*cos(x)*sin(x)
ans =
cos(x)*cos(y) - sin(x)*sin(y)
ans =
x^4 - 7*x^3
ans =
x^6 - 8*x^5 + 15*x^4
Expanding and Collecting Equations in Octave
Youneed to have symbolic package, whichprovides expand and the collect command to expand and collect
anequation, respectively. The following example demonstrates the concepts:
Whenyouwork withmany symbolic functions, youshould declare that your variables are symbolic but Octave has
different approachto define symbolic variables. Notice the use of Sin and Cos, they are also defined insymbolic
package.
Create a script file and type the following code:
% first of all load the package, make sure its installed.
pkg load symbolic
% make symbols module available
symbols
% define symbolic variables
x = sym ('x');
y = sym ('y');
z = sym ('z');
% expanding equations
expand((x-5)*(x+9))
expand((x+2)*(x-3)*(x-5)*(x+7))
expand(Sin(2*x))
expand(Cos(x+y))
% collecting equations
collect(x^3 *(x-7), z)
collect(x^4*(x-3)*(x-5), z)
Whenyourunthe file, it displays the following result:
ans =
-45.0+x^2+(4.0)*x
ans =
210.0+x^4-(43.0)*x^2+x^3+(23.0)*x
ans =
sin((2.0)*x)
ans =
cos(y+x)
ans =
x^(3.0)*(-7.0+x)
ans =
(-3.0+x)*x^(4.0)*(-5.0+x)
Factorization and Simplification of Algebraic Expressions
The factor command factorizes anexpressionand the simplify command simplifies anexpression. The
following example demonstrates the concept:
Example
Create a script file and type the following code:
syms x
syms y
factor(x^3 - y^3)
factor([x^2-y^2,x^3+y^3])
simplify((x^4-16)/(x^2-4))
Whenyourunthe file, it displays the following result:
ans =
(x - y)*(x^2 + x*y + y^2)
ans =
[ (x - y)*(x + y), (x + y)*(x^2 - x*y + y^2)]
ans =
x^2 + 4

Contenu connexe

Tendances

Module 4 exponential and logarithmic functions
Module 4   exponential and logarithmic functionsModule 4   exponential and logarithmic functions
Module 4 exponential and logarithmic functionsAya Chavez
 
The Exponential and natural log functions
The Exponential and natural log functionsThe Exponential and natural log functions
The Exponential and natural log functionsJJkedst
 
S1 3 derivadas_resueltas
S1 3 derivadas_resueltasS1 3 derivadas_resueltas
S1 3 derivadas_resueltasjesquerrev1
 
Module 3 exponential and logarithmic functions
Module 3   exponential and logarithmic functionsModule 3   exponential and logarithmic functions
Module 3 exponential and logarithmic functionsdionesioable
 
Difrentiation
DifrentiationDifrentiation
Difrentiationlecturer
 
4.1 inverse functions
4.1 inverse functions4.1 inverse functions
4.1 inverse functionsmath260
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomialsmath260
 
Module 2 quadratic functions
Module 2   quadratic functionsModule 2   quadratic functions
Module 2 quadratic functionsdionesioable
 
Dividing polynomials
Dividing polynomialsDividing polynomials
Dividing polynomialssalvie alvaro
 
Notes - Graphs of Polynomials
Notes - Graphs of PolynomialsNotes - Graphs of Polynomials
Notes - Graphs of PolynomialsLori Rapp
 
Pt 3&4 turunan fungsi implisit dan cyclometri
Pt 3&4 turunan fungsi implisit dan cyclometriPt 3&4 turunan fungsi implisit dan cyclometri
Pt 3&4 turunan fungsi implisit dan cyclometrilecturer
 
01 derivadas
01   derivadas01   derivadas
01 derivadasklorofila
 
2.4 grapgs of second degree functions
2.4 grapgs of second degree functions2.4 grapgs of second degree functions
2.4 grapgs of second degree functionsmath260
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functionsdionesioable
 
13 graphs of factorable polynomials x
13 graphs of factorable polynomials x13 graphs of factorable polynomials x
13 graphs of factorable polynomials xmath260
 

Tendances (20)

Jackson d.e.v.
Jackson d.e.v.Jackson d.e.v.
Jackson d.e.v.
 
Module 4 exponential and logarithmic functions
Module 4   exponential and logarithmic functionsModule 4   exponential and logarithmic functions
Module 4 exponential and logarithmic functions
 
0303 ch 3 day 3
0303 ch 3 day 30303 ch 3 day 3
0303 ch 3 day 3
 
The Exponential and natural log functions
The Exponential and natural log functionsThe Exponential and natural log functions
The Exponential and natural log functions
 
S1 3 derivadas_resueltas
S1 3 derivadas_resueltasS1 3 derivadas_resueltas
S1 3 derivadas_resueltas
 
Module 3 exponential and logarithmic functions
Module 3   exponential and logarithmic functionsModule 3   exponential and logarithmic functions
Module 3 exponential and logarithmic functions
 
Difrentiation
DifrentiationDifrentiation
Difrentiation
 
Graph a function
Graph a functionGraph a function
Graph a function
 
4.1 inverse functions
4.1 inverse functions4.1 inverse functions
4.1 inverse functions
 
2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials2.9 graphs of factorable polynomials
2.9 graphs of factorable polynomials
 
Module 2 quadratic functions
Module 2   quadratic functionsModule 2   quadratic functions
Module 2 quadratic functions
 
Dividing polynomials
Dividing polynomialsDividing polynomials
Dividing polynomials
 
Notes - Graphs of Polynomials
Notes - Graphs of PolynomialsNotes - Graphs of Polynomials
Notes - Graphs of Polynomials
 
Pt 3&4 turunan fungsi implisit dan cyclometri
Pt 3&4 turunan fungsi implisit dan cyclometriPt 3&4 turunan fungsi implisit dan cyclometri
Pt 3&4 turunan fungsi implisit dan cyclometri
 
Functions limits and continuity
Functions limits and continuityFunctions limits and continuity
Functions limits and continuity
 
01 derivadas
01   derivadas01   derivadas
01 derivadas
 
Functions
FunctionsFunctions
Functions
 
2.4 grapgs of second degree functions
2.4 grapgs of second degree functions2.4 grapgs of second degree functions
2.4 grapgs of second degree functions
 
Module 2 exponential functions
Module 2   exponential functionsModule 2   exponential functions
Module 2 exponential functions
 
13 graphs of factorable polynomials x
13 graphs of factorable polynomials x13 graphs of factorable polynomials x
13 graphs of factorable polynomials x
 

En vedette

En vedette (17)

Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
C24 company overview brochure lowres
C24 company overview brochure lowresC24 company overview brochure lowres
C24 company overview brochure lowres
 
Effective resume writing
Effective resume writingEffective resume writing
Effective resume writing
 
Matlab calculus
Matlab calculusMatlab calculus
Matlab calculus
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
C24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big dataC24 bi datasheet leading in the legal sector with big data
C24 bi datasheet leading in the legal sector with big data
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
C24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3ppC24 wright hassall casestudy a4 3pp
C24 wright hassall casestudy a4 3pp
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365C24 Arthur Terry Case Study 365
C24 Arthur Terry Case Study 365
 

Similaire à Matlab algebra

INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
Chapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptxChapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptxEyob Adugnaw
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Bryan O'Sullivan
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Reviewhassaanciit
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxSALU18
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 
Analytic Geometry Period 1
Analytic Geometry Period 1Analytic Geometry Period 1
Analytic Geometry Period 1ingroy
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that LetterKevlin Henney
 
Slope Fields For Snowy Days
Slope Fields For Snowy DaysSlope Fields For Snowy Days
Slope Fields For Snowy DaysAlexander Burt
 

Similaire à Matlab algebra (20)

Signals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptxSignals and Systems Homework Help.pptx
Signals and Systems Homework Help.pptx
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Matlab1
Matlab1Matlab1
Matlab1
 
Chapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptxChapter 1 MATLAB Fundamentals easy .pptx
Chapter 1 MATLAB Fundamentals easy .pptx
 
Real World Haskell: Lecture 2
Real World Haskell: Lecture 2Real World Haskell: Lecture 2
Real World Haskell: Lecture 2
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
Lesson 8
Lesson 8Lesson 8
Lesson 8
 
Calculus - Functions Review
Calculus - Functions ReviewCalculus - Functions Review
Calculus - Functions Review
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 
Matlab Sample Assignment Solution
Matlab Sample Assignment SolutionMatlab Sample Assignment Solution
Matlab Sample Assignment Solution
 
Lecture three
Lecture threeLecture three
Lecture three
 
bobok
bobokbobok
bobok
 
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docxerror 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
error 2.pdf101316, 6(46 PM01_errorPage 1 of 5http.docx
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Analytic Geometry Period 1
Analytic Geometry Period 1Analytic Geometry Period 1
Analytic Geometry Period 1
 
Lambda? You Keep Using that Letter
Lambda? You Keep Using that LetterLambda? You Keep Using that Letter
Lambda? You Keep Using that Letter
 
Recursion Lecture in Java
Recursion Lecture in JavaRecursion Lecture in Java
Recursion Lecture in Java
 
Slope Fields For Snowy Days
Slope Fields For Snowy DaysSlope Fields For Snowy Days
Slope Fields For Snowy Days
 

Plus de pramodkumar1804 (13)

Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
Matlab colon notation
Matlab colon notationMatlab colon notation
Matlab colon notation
 
Matlab vectors
Matlab vectorsMatlab vectors
Matlab vectors
 

Dernier

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinojohnmickonozaleda
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomnelietumpap1
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfMr Bounab Samir
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfphamnguyenenglishnb
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 

Dernier (20)

Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Raw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptxRaw materials used in Herbal Cosmetics.pptx
Raw materials used in Herbal Cosmetics.pptx
 
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
FILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipinoFILIPINO PSYCHology sikolohiyang pilipino
FILIPINO PSYCHology sikolohiyang pilipino
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
ENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choomENGLISH6-Q4-W3.pptxqurter our high choom
ENGLISH6-Q4-W3.pptxqurter our high choom
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdfLike-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
Like-prefer-love -hate+verb+ing & silent letters & citizenship text.pdf
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdfAMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
AMERICAN LANGUAGE HUB_Level2_Student'sBook_Answerkey.pdf
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptxLEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
LEFT_ON_C'N_ PRELIMS_EL_DORADO_2024.pptx
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 

Matlab algebra

  • 1. http://www.tutorialspoint.com/matlab/matlab_alg ebra.htm Copyright © tutorialspoint.com MATLAB - ALGEBRA So far, we have seenthat allthe examples work inMATLAB as wellas its GNU, alternatively called Octave. But for solving basic algebraic equations, bothMATLAB and Octave are little different, so we willtry to cover MATLAB and Octave inseparate sections. We willalso discuss factorizing and simplificationof algebraic expressions. Solving Basic Algebraic Equations in MATLAB The solve command is used for solving algebraic equations. Inits simplest form, the solve functiontakes the equationenclosed inquotes as anargument. For example, let us solve for x inthe equationx-5 = 0 solve('x-5=0') MATLAB willexecute the above statement and returnthe following result: ans = 5 Youcanalso callthe solve functionas: y = solve('x-5 = 0') MATLAB willexecute the above statement and returnthe following result: y = 5 Youmay evennot include the right hand side of the equation: solve('x-5') MATLAB willexecute the above statement and returnthe following result: ans = 5 If the equationinvolves multiple symbols, thenMATLAB by default assumes that youare solving for x, however, the solve command has another form: solve(equation, variable) where, youcanalso mentionthe variable. For example, let us solve the equationv – u– 3t2 = 0, for v. Inthis case, we should write: solve('v-u-3*t^2=0', 'v') MATLAB willexecute the above statement and returnthe following result: ans = 3*t^2 + u Solving Basic Algebraic Equations in Octave
  • 2. The roots command is used for solving algebraic equations inOctave and youcanwrite above examples as follows: For example, let us solve for x inthe equationx-5 = 0 roots([1, -5]) Octave willexecute the above statement and returnthe following result: ans = 5 Youcanalso callthe solve functionas: y = roots([1, -5]) Octave willexecute the above statement and returnthe following result: y = 5 Solving Quadratic Equations in MATLAB The solve command canalso solve higher order equations. It is oftenused to solve quadratic equations. The functionreturns the roots of the equationinanarray. The following example solves the quadratic equationx2 -7x +12 = 0. Create a script file and type the following code: eq = 'x^2 -7*x + 12 = 0'; s = solve(eq); disp('The first root is: '), disp(s(1)); disp('The second root is: '), disp(s(2)); Whenyourunthe file, it displays the following result: The first root is: 3 The second root is: 4 Solving Quadratic Equations in Octave The following example solves the quadratic equationx2 -7x +12 = 0 inOctave. Create a script file and type the following code: s = roots([1, -7, 12]); disp('The first root is: '), disp(s(1)); disp('The second root is: '), disp(s(2)); Whenyourunthe file, it displays the following result: The first root is: 4 The second root is: 3 Solving Higher Order Equations in MATLAB The solve command canalso solve higher order equations. For example, let us solve a cubic equationas (x- 3)2(x-7) = 0
  • 3. solve('(x-3)^2*(x-7)=0') MATLAB willexecute the above statement and returnthe following result: ans = 3 3 7 Incase of higher order equations, roots are long containing many terms. Youcanget the numericalvalue of such roots by converting themto double. The following example solves the fourthorder equationx4 − 7x3 + 3x2 − 5x + 9 = 0. Create a script file and type the following code: eq = 'x^4 - 7*x^3 + 3*x^2 - 5*x + 9 = 0'; s = solve(eq); disp('The first root is: '), disp(s(1)); disp('The second root is: '), disp(s(2)); disp('The third root is: '), disp(s(3)); disp('The fourth root is: '), disp(s(4)); % converting the roots to double type disp('Numeric value of first root'), disp(double(s(1))); disp('Numeric value of second root'), disp(double(s(2))); disp('Numeric value of third root'), disp(double(s(3))); disp('Numeric value of fourth root'), disp(double(s(4))); Whenyourunthe file, it returns the following result: The first root is: 6.630396332390718431485053218985 The second root is: 1.0597804633025896291682772499885 The third root is: - 0.34508839784665403032666523448675 - 1.0778362954630176596831109269793*i The fourth root is: - 0.34508839784665403032666523448675 + 1.0778362954630176596831109269793*i Numeric value of first root 6.6304 Numeric value of second root 1.0598 Numeric value of third root -0.3451 - 1.0778i Numeric value of fourth root -0.3451 + 1.0778i Please note that the last two roots are complex numbers. Solving Higher Order Equations in Octave The following example solves the fourthorder equationx4 − 7x3 + 3x2 − 5x + 9 = 0. Create a script file and type the following code: v = [1, -7, 3, -5, 9]; s = roots(v); % converting the roots to double type disp('Numeric value of first root'), disp(double(s(1))); disp('Numeric value of second root'), disp(double(s(2))); disp('Numeric value of third root'), disp(double(s(3))); disp('Numeric value of fourth root'), disp(double(s(4))); Whenyourunthe file, it returns the following result:
  • 4. Numeric value of first root 6.6304 Numeric value of second root -0.34509 + 1.07784i Numeric value of third root -0.34509 - 1.07784i Numeric value of fourth root 1.0598 Solving System of Equations in MATLAB The solve command canalso be used to generate solutions of systems of equations involving more thanone variables. Let us take up a simple example to demonstrate this use. Let us solve the equations: 5x + 9y = 5 3x – 6y = 4 Create a script file and type the following code: s = solve('5*x + 9*y = 5','3*x - 6*y = 4'); s.x s.y Whenyourunthe file, it displays the following result: ans = 22/19 ans = -5/57 Insame way, youcansolve larger linear systems. Consider the following set of equations: x + 3y -2z = 5 3x + 5y + 6z = 7 2x + 4y + 3z = 8 Solving System of Equations in Octave We have a little different approachto solve a systemof 'n' linear equations in'n' unknowns. Let us take up a simple example to demonstrate this use. Let us solve the equations: 5x + 9y = 5 3x – 6y = 4 Sucha systemof linear equations canbe writtenas the single matrix equationAx = b, where A is the coefficient matrix, b is the columnvector containing the right-hand side of the linear equations and x is the columnvector representing the solutionas showninthe below program: Create a script file and type the following code: A = [5, 9; 3, -6]; b = [5;4]; A b Whenyourunthe file, it displays the following result: ans =
  • 5. 1.157895 -0.087719 Insame way, youcansolve larger linear systems as givenbelow: x + 3y -2z = 5 3x + 5y + 6z = 7 2x + 4y + 3z = 8 Expanding and Collecting Equations in MATLAB The expand and the collect command expands and collects anequationrespectively. The following example demonstrates the concepts: Whenyouwork withmany symbolic functions, youshould declare that your variables are symbolic. Create a script file and type the following code: syms x %symbolic variable x syms y %symbolic variable x % expanding equations expand((x-5)*(x+9)) expand((x+2)*(x-3)*(x-5)*(x+7)) expand(sin(2*x)) expand(cos(x+y)) % collecting equations collect(x^3 *(x-7)) collect(x^4*(x-3)*(x-5)) Whenyourunthe file, it displays the following result: ans = x^2 + 4*x - 45 ans = x^4 + x^3 - 43*x^2 + 23*x + 210 ans = 2*cos(x)*sin(x) ans = cos(x)*cos(y) - sin(x)*sin(y) ans = x^4 - 7*x^3 ans = x^6 - 8*x^5 + 15*x^4 Expanding and Collecting Equations in Octave Youneed to have symbolic package, whichprovides expand and the collect command to expand and collect anequation, respectively. The following example demonstrates the concepts: Whenyouwork withmany symbolic functions, youshould declare that your variables are symbolic but Octave has different approachto define symbolic variables. Notice the use of Sin and Cos, they are also defined insymbolic package. Create a script file and type the following code: % first of all load the package, make sure its installed. pkg load symbolic % make symbols module available symbols % define symbolic variables x = sym ('x'); y = sym ('y');
  • 6. z = sym ('z'); % expanding equations expand((x-5)*(x+9)) expand((x+2)*(x-3)*(x-5)*(x+7)) expand(Sin(2*x)) expand(Cos(x+y)) % collecting equations collect(x^3 *(x-7), z) collect(x^4*(x-3)*(x-5), z) Whenyourunthe file, it displays the following result: ans = -45.0+x^2+(4.0)*x ans = 210.0+x^4-(43.0)*x^2+x^3+(23.0)*x ans = sin((2.0)*x) ans = cos(y+x) ans = x^(3.0)*(-7.0+x) ans = (-3.0+x)*x^(4.0)*(-5.0+x) Factorization and Simplification of Algebraic Expressions The factor command factorizes anexpressionand the simplify command simplifies anexpression. The following example demonstrates the concept: Example Create a script file and type the following code: syms x syms y factor(x^3 - y^3) factor([x^2-y^2,x^3+y^3]) simplify((x^4-16)/(x^2-4)) Whenyourunthe file, it displays the following result: ans = (x - y)*(x^2 + x*y + y^2) ans = [ (x - y)*(x + y), (x + y)*(x^2 - x*y + y^2)] ans = x^2 + 4