[go: up one dir, main page]

0% found this document useful (0 votes)
21 views1 page

Demo Matlab3

The document provides a series of MATLAB demonstrations focusing on symbolic mathematics, including simplification of expressions, solving equations, matrix operations, and eigenvalue calculations. It illustrates how to handle single and systems of equations, perform matrix multiplication, find inverses, and compute eigenvalues and characteristic polynomials of matrices. The examples are structured to show the syntax and functionality of MATLAB for symbolic computation.

Uploaded by

dipanjanbarman79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views1 page

Demo Matlab3

The document provides a series of MATLAB demonstrations focusing on symbolic mathematics, including simplification of expressions, solving equations, matrix operations, and eigenvalue calculations. It illustrates how to handle single and systems of equations, perform matrix multiplication, find inverses, and compute eigenvalues and characteristic polynomials of matrices. The examples are structured to show the syntax and functionality of MATLAB for symbolic computation.

Uploaded by

dipanjanbarman79
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

DEMO MATLAB3

Friday, 9 April 2021 1:57 PM

syms x c a b
simplify(2*sin(x)^2 - cos(x)^2)
simplify(exp(c*log(sqrt(a+b))))
simplify(sqrt(x^2)) BARBOVJGARI
% Compare with above
simplify(sqrt(x^2),'IgnoreAnalyticConstraints',true)
% controls the level of mathematical rigor to use on the
analytical constraints
%while simplifying. The options for VAL are TRUE or
FALSE,
%TRUE to relax the level of mathematical rigor
simplify(sqrt(a^2 + 2*a*b + b^2))
simplify(sqrt(a^2 + 2*a*b + b^
2),'IgnoreAnalyticConstraints',true)

% solve single variable eqn


syms x
eqn = x^2 == x - 1;
S = solve(eqn,x) % may be there is no
solution, even then it will plot 2
eqns
%Plot the left and the right sides of
the equation. Observe that the
equation also has a positive
solution.
fplot([lhs(eqn) rhs(eqn)], [-2 2]) %
x axis range given
figure;
fplot(x^2,[-3 3]);
hold on
fplot(x-1,[-3 3]);

%Solve a system of equations to return the


solutions in a structure array.
clc
syms u v
eqns = [2*u^2 + v == 0, u - v == 1];
S = solve(eqns,[u v])
%S = struct with fields:
% u: [1x1 sym]
% v: [1x1 sym]
% Access the solutions by addressing the
elements of the structure.
x= 2*u^2 + v
y=u - v
disp('solve for u');
S.u
disp('solve for v');
S.v

% demo Matrix multiplication


syms x
A = [x, 2*x^2, 3*x^3, 4*x^4] % 1X4 mat
B = [1/x; 2/x^2; 3/x^3; 4/x^4] % 4X1 mat
%Find the matrix product of these two vectors.
A*B
%Multiply Two Matrices, a 4-by-3 matrix and a 3-by-2
matrix.
A = sym('a%d%d', [4 3])
B = sym('b%d%d', [3 2])
% how elements are written for A & B
% Multiply A by B
A*B

% Demo to find Inverse of symbolic matrix


clc
A = sym([2 -1 0; -1 2 -1; 0 -1 2]);% row1; row2;
row3
inv(A)
A*inv(A)
%Compute the inverse of the following symbolic
matrix.
syms a b c d
A = [a b; c d]
inv(A)
% Try also
A = [a 1; 1-c d];
inv(A)
b=[1; 2]
%AX=b
x = inv(A)*b

% Demo for Matrix eigen values. Given Mat


clc
A=[1 2 1
4 2 1
1 1 1];
% to find a symbolic vector containing the
eigenvalues of the square symbolic matrix A.
lambda = eig(A)
%to get matrices V and D. The columns of V
present eigenvectors of A.
%The diagonal matrix D contains eigenvalues.
[V,D] = eig(A)
% The determinant is
d = det(A)
% with symbol a
A=[a 1 0
0 2 1
0 1 0];
lambda = eig(A)
[V,D]= eig(A)

% Charac eqn demo


%charpoly(A) returns a vector of coefficients of the
characteristic polynomial of A.
% If A is a symbolic matrix, charpoly returns a symbolic
vector.
% Otherwise, it returns a vector of double-precision
values
clc
A = [1 0 0; 0 1 0; 0 0 1]
% Compute the coefficients of the characteristic
polynomial of A
disp('coeff of the ch poly')
charpoly(A)
charpoly(A,x)
lambda=eig(A)
% Compute the characteristic polynomial of the matrix A in
terms of x.
syms x a
A = sym([a 0 0; 0 1 0; 0 0 1]);
disp('write down the eqn in terms of x and coefficient a')
polyA = charpoly(A,x)
disp('eigen values of the above are')
eigenA = solve(polyA)
% Compute the minimal polynomial of the matrix A
disp('MINIMUM POLYNOMIAL IS')
P = minpoly(A,x)
eigenA = solve(P)
%[V,J]=jordan(A)

You might also like