Matlab Algebra

Up until now, we have seen that every one of the models work in MATLAB just as its GNU, then again called Octave. In any case, for addressing fundamental mathematical conditions, both MATLAB and Octave are minimal unique, so we will attempt to cover in MATLAB and alternative Octave in independent areas.

Variable based math that is ALGEBRA is all about the investigation of numerical images and rules for controlling these symbol images. Here factors variables are utilized to store/address amounts. There are sure in-assembled strategies in Matlab to address polynomial math conditions. Underlying foundations of conditions, tackling for x, working on an articulation are a few things we can act in MATLAB.

Matlab algebra

Basic Algebraic Equations Solving in MATLAB

For solving and finding algebraic equations solutions, the solve function is used. In its easiest format, the function called solve(), takes arguments as the equation is in “ “ quotes.

Example, let us find solution for y in the equation y-6 = 0

solve('y-6=0')

The above statement MATLAB will execute and return result as follows-

ans =
   6

You can also use above solve function as follows –

We Created a script file code to illustrate the above function-

%this  MATLAB program is used to illustrate
% the solve function to solve a equation


syms y


% Below eqn is nothing but
% y-29 = 0
eqn = y-29 == 0;
P = solve(eqn,y);


disp(P)

Output:

Matlab algebra

Factorization of an expression and Simplification:

To find factors of or simplify an expression we use factor() function and simplify() function respectively. When we use many symbolic functions in our code, we must declare that variables as symbolic.

Factor Syntax:

factor(any type of expression)
    or
factor(any_integer)

Simplify Syntax:

simplify(any type of expression)

If an expression is passed into factor() function, then it returns an array of factors. If an integer is passed into factor() function, then it returns prime factorization of the given integer.

We Created a script file code to illustrate the above function-

% to find factors to illustrate
% factor function 


syms p
syms q


% prime factorization of
% any given integer
factor(29)


% factors of
% expressions p^4-q^4
factor(p^4-q^4)
factor(p^6-1)

Output:

ans =


    29
 
ans =
 
[p - q, p + q, p^2 + q^2]
 
 
ans =
 
[p - 1, p + 1, p^2 + p + 1, p^2 - p + 1]

Solve linear system of linear equation

A linear system can be solved with help of both function mldivide and linsolve to think about execution.

mldivide is the prescribed method to address most direct frameworks of conditions in MATLAB ®. Be that as it may, the capacity plays out a few keeps an eye on the info lattice to decide if it has any exceptional properties. In the event that you think about the properties of the coefficient grid early, then, at that point you can utilize linsolve to stay away from tedious checks for enormous matrices.

Utility function helps in solving matrix equation easily

Mldivide “\”

To Solve linear equations systems like  Px = Q for x

Syntax

x=P\Q
x= mldivide(P,Q)

Description

x = P\Q solves the given linear equations P*x = Q. The matrices P and Q must have the same rows. MATLAB® sends a message for warning if P is nearly singular, but gives the calculation regardless of any issue.

Example:

A1 = magic(4);
B1 = [14; 14; 14; 14];
x = A1\B1

Output:

A1 = magic(4);
B1 = [14; 14; 14;14];
x = A1\B1
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  4.625929e-18. 
x =


    0.3725
    0.2941
    0.5294
    0.4510

Linsolve()

It is used to solve the linear system of equations.

Syntax

X= linsolve(P,Q)
X= limsolve(P,Q,opts)
[x,r] =linsolve(_________)

Description

X= linsolve(p,q) solves the linear system equation pX = q using any of these methods:

Example

A1 = tril(magic(1e4));
opts.LT = true;
b1 = ones(size(A1,2),1);
tic
x1 = A1\b1; 
o1 = toc
tic
x2 = linsolve(A1,b1,opts);
o2 = toc    
speedup = o1/o2

Output:

t1 =


    0.0825




t2 =


    0.0279
speedup = t1/t2


speedup =


    2.9545

Solving Quadratic Equations in MATLAB

To solve higher order equations, we use the solve() function. Roots of the equation is returned in the form of an array.

To solves the quadratic equation x2 -8x +16 = 0.

We Created a script file code to illustrate the above function-

eq1 = 'x^2 -8*x + 16 = 0';
s1 = solve(eq1);
disp('The first root of the quadratic equation x2 -8x +16 = 0.is: '), disp(s1(1));
disp('The second root of the quadratic equation x2 -8x +16 = 0. is: '), disp(s1(2));

After we run the above script file, we get the following expected result -

The first root of the quadratic equation x2 -8x +24 = 0.is: 4
The first root of the quadratic equation x2 -8x +24 = 0.is: 4

MATLAB Higher Order Equations solution

Roots are lengthy of higher order degree equations, and may contain many terms. Roots values can be obtained by converting to double datatype. The fourth order degree equation is solved x4 - 8x3 + 3x2 - 5x + 9 = 0.

We have Created a script file code -

eq = 'x^4 - 7*x^3 + 3*x^2 - 5*x + 9 = 0';
s = solve(eq);
disp('The first root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is'), disp(s(1));
disp(' The second root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is'), disp(s(2));
disp(' The third root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 .is''), disp(s(3));
disp(' The fourth root of the quadratic equation x4 – 8 x3 + 3x2 - 5x + 9 = 0 .is''), disp(s(4));


% converting equation roots to double data type
disp(' The first root  numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 .is''), disp(double(s(1)));
disp(' The second root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 .is''), disp(double(s(2)));
disp(' The third root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 .is''), disp(double(s(3)));
disp(' The fourth root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 .is''), disp(double(s(4)));

After we run the above script file, we get the following expected result -

The first root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is 6.630396332390718431485053218985
The second root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is 1.0597804633025896291682772499885
The third root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is - 0.34508839784665403032666523448675 - 1.0778362954630176596831109269793*i
The fourth root of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is - 0.34508839784665403032666523448675 + 1.0778362954630176596831109269793*i
The first root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is   6.6304
The second root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is   1.0598
The third root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is   -0.3451 - 1.0778i
The fouth root numeric value of the quadratic equation x4 - 8x3 + 3x2 - 5x + 9 = 0 is   -0.3451 + 1.0778i

MATLAB Equations - Expanding and Collecting

The expand() function and the collect() function expands exponentially and collects an equation variables respectively. The following instances demonstrates the function usage clearly.

When we will work with different symbolic functions, we must declare that the variables are symbolic in nature.

We Created a script file code to illustrate the above function-

syms p   %representing symbolic variable p
syms q   %representing symbolic variable p
% we are expanding equations
expand((p-6)*(p+9))
expand((p+2)*(p-3)*(p-5)*(p+7))
expand(sin(3*p))
expand(cos(p+q))
 
% collecting equations
collect(p^5 *(p-7))
collect(p^4*(p-3)*(p-5))

After we run the above script file, we get the following expected result -

ans =
 
p^2 + 3*p - 54
 
 
ans =
 
p^4 + p^3 - 43*p^2 + 23*p + 210
 
 
ans =
 
4*cos(p)^2*sin(p) - sin(p)
 
 
ans =
 
cos(p)*cos(q) - sin(p)*sin(q)
 
 
ans =
 
p^6 - 7*p^5
 
 
ans =
 
p^6 - 8*p^5 + 15 *p ^ 4
 
 
   x ^ 6 – 8 * x ^ 5 + 15* x ^ 4

Related Topics

Matlab function

Introduction: Functions in MATLAB are composed with code that link one variable with another, and yielded output is connected precisely to one specific information that shapes a significant piece of any...

6 minutes read.

Differentiation in Matlab

Differentiation in Mathematics In maths, Derivatives are an essential device of math or calculus. For instance, derivative of the situation of a moving article regarding time is the item's speed: this...

6 minutes read.

MATLAB’s Array

What is an Array? An array is a collection of similar datatype elements in contiguous memory location. Every element in array is stored with an index number starting from 0. First...

4 minutes read.

MATLAB Strings

You can address text in MATLAB utilizing string exhibits. Every component of a string exhibit stores a grouping of characters. The arrangements can have various lengths without cushioning, for example,...

5 minutes read.

Matlab Square Wave Signal Generation

What is Square Wave signal Generator? A “square wave” is a sort of non-sinusoidal waveform, most normally experienced in gadgets and sign preparing. An optimal square wave substitutes consistently and momentarily...

3 minutes read.

matlab polynomials

In mathematics, a polynomial is an articulation comprising of indeterminates factors and the respective coefficients, that includes just the tasks of augmentation, expansion, deduction, and non-negative whole number exponentiation of...

4 minutes read.

MATLAB Loops

Loops in programming Concept of looping is used to execute instructions repeatedly. It helps coders to reduce lines of code by setting a condition. In looping first a condition is fixed,...

3 minutes read.

MATLAB Butterworth filter

What is Butterworth filter? The Butterworth channel is a kind of sign preparing channel intended to have a recurrence reaction as level as conceivable in the passband. It is likewise alluded...

3 minutes read.

MATLAB Variables

What are variables? A variable is a storage location or a container to store or hold data. In programming, variables are used to reservedata created by the programmers so that it...

4 minutes read.

MATLAB Tutorial

Introduction of MATLAB In this MATLAB(stands for matrix laboratory) tutorial, we will cover core concepts of MATLAB and provide a solid foundation to enhance high computing skills. We are going to...

4 minutes read.

Matlab Algebra

Up until now, we have seen that every one of the models work in MATLAB just as its GNU, then again called Octave. In any case, for addressing fundamental mathematical...

6 minutes read.

MATLAB Features

MATLAB Features MATLAB (abbreviation for matrix laboratory) is an interactive programming environment that eases high-power computations in the IT world. Initially, it was developed with the intention of matrix calculation only....

4 minutes read.

MATLAB vs Other Languages

MATLAB vs Other Languages If we try to find which is the best computer programming languages, the answer is not straightforward, and that might sound similar to asking which is the...

3 minutes read.

Matlab DFT and IDFT

Matlab Program- (DFT and IDFT of a sequence) Program for DFT (Discrete Fourier change) and IDFT (Inverse discrete Fourier change) of a sequence. Program explanation: In Arithmetic, the discrete Fourier change (DFT) changes...

3 minutes read.

Matlab Graphic image

Matlab’s Graphic image Images are stored as arrays of numeric data in MATLAB® environment, so you can perform various sort of analysis on them to better visualize it. Picture Processing applications are given...

3 minutes read.

MATLAB Vector

Introduction to MATLAB vector Vectors are one of the representations of arrays. It tends to be addressed in two different ways line(row) vector and section(column) vector. A vector is defined as...

5 minutes read.

MATLAB Gaussian Pulse

Gaussian pulse shape description: The diagram of a Gaussian is a trademark symmetric "ringer bend" shape. The boundary an is the stature of the bend's pinnacle, b is the situation of...

3 minutes read.

MATLAB Operators

What is an Operator? A specific operation is performed by using a symbol which is called an operator. Example: A+B, where A, B are called operand and '+' is called operator. If you...

8 minutes read.

Matlab Matrix

Matlab Matrix What is a Matrix? a rectangular array of expressions arranged in particular rows and columns that is treated as a solitary substance and controlled by specific standards. MatlabMatrix A Framework called matrix,...

5 minutes read.

MATLAB special graphic function

In this section, we portray a greater amount of MATLAB's illustrations graphic functions and the most well-known methods of controlling and redoing graphics. Let’s type help designs, help graph2d (for...

7 minutes read.