0% found this document useful (0 votes)
3 views2 pages

KGEC Control Lab Programs Only

The document outlines three experiments involving matrix manipulations and control systems using MATLAB. The first experiment focuses on basic matrix operations such as finding dimensions, counting occurrences, and modifying elements. The second experiment covers matrix arithmetic, including addition, subtraction, multiplication, and generating random numbers, while the third experiment introduces transfer functions and control system concepts using MATLAB's Simulink.

Uploaded by

samriddhasen46
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)
3 views2 pages

KGEC Control Lab Programs Only

The document outlines three experiments involving matrix manipulations and control systems using MATLAB. The first experiment focuses on basic matrix operations such as finding dimensions, counting occurrences, and modifying elements. The second experiment covers matrix arithmetic, including addition, subtraction, multiplication, and generating random numbers, while the third experiment introduces transfer functions and control system concepts using MATLAB's Simulink.

Uploaded by

samriddhasen46
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

Name of the Experiment: Basic manipulations on Matrix

Objectives:
(a) Write a MATLAB program to find the number of rows and columns of a matrix
(b) Write a MATLAB program to find the number occurrence of an element in a matrix
(c) Write a MATLAB program to change the value of an element to a new value of a matrix
Program:
clc; %% clear the command window
clear all; %% clear the workspace
A= [1, 5, 6; 2, 4, 3; 4, 5, 8]; %% input matrix
A(2,3)
%%% To know the size of matrix %%%
[b,c]=size(A);
b1=size(A,1); %% no of rows
c1=size(A,2); %% no of columns
%%% To know number of occurrence of a value in matrix %%%
f=0;
for i=1:b
for j=1:c
if A(i,j)==5
f=f+1;
end
end
end
display(f);
%%% Alternative To know number of occurrence of a value in matrix %%%
d=sum(A(:)==5);
%%% To add elements of matrix %%%
d=sum(A(:)==5);
d1=sum(A(1,:)); %% summation of all elements in first row
d2=sum(sum(A(1:2,:))); %% summation of all elements in first two rows
d3=sum(A(:,3)); %% summation of all elements in third column
d4=sum(A(:)); %% summation of all elements in the matrix
%% Alternative to sum of all elements in the matrix
s=0;
for i=1:b
for j=1:c
s=s+A(i,j);
end
end
sum(A(1,:)); %% summation of all elements in first row
sum(sum(A(1:2,:))); %% summation of all elements in first two rows
sum(A(:,3));
sum(A(:));
%%%% To change any element value %%%
for i=1:b
for j=1:c
if A(i,j)==5
A(i,j)=10;
end
end
end

Name of the Experiment: Basic operations on Matrix


Objectives:
(a) WAP in MATLAB to add two matrices
(b) WAP in MATLAB to subtract one matrix from other matrix
(c) WAP in MATLAB to multiply two matrices
(d) WAP in MATLAB to take transpose of a matrix
(e) WAP in MATLAB to inverse a matrix
(f) WAP in MATLAB to randomly generate numbers, integers.
(g) WAP in MATLAB to generate array of ones and zeros.
(h) WAP in MATLAB to square each elements of an array
(i) WAP in MATLAB to find a number in an array
Program:
clc; %% clear the command window
clear all; %% clear the workspace
%%% some operations on matrix %%%
A= [1, 5, 6; 2, 4, 3; 4, 5, 8];
B=[3, 4, 6; 2, 4, 1; 9, 5, 7];
C=A+B; %%% addition of two matrices
C2=A-B; %% subtraction of one matrix from another matrix
E=A*B; %% multiplication of two matrices
D=[1,3,5];
E1=[2,4,3];
F=D.*E1;% elementwise multiplication
G=A';
G1=transpose(A); % transpose of matrix
H=inv(A); % inverse of matrix
%%% some operations on array %%%
R1=rand(5,1);
R2=randi([2,10],1,5);
Q1=zeros(1,4);
Q2=ones(1,4);
P=[1,3,4,0,6,7,8];
T1=P.^2; % elementwise square of array
m=find(P==0);

Name of the Experiment: Representation of pole zero and transfer function of control system.

1. Objectives:
(a) To familiarize with the MATLAB Simulink and its control system tool box
(b) WAP in MATLAB to determine transfer function from pole, zero and gain
(c) WAP in MATLAB to determine transfer function from numerator and denominator coefficients
(d) WAP in MATLAB to directly write the transfer function in s-domain
(e) WAP in MATLAB to obtain closed loop transfer function from open loop transfer function

4. Program:
clc;
clear all;
% TF from to numerator & denomenator coefficients %
% Input Numerator Coefficients %
num = [2 3];
% Input Denominator Coefficients %
den = [3 5 4 1];
sys = tf(num,den)
% TF from pole, zero, gain %
% Input zeros %
Z=[1];
% Input poles %
P=[-2 -3-];
% Input gain %
K=[2];
[num2 den2] = zp2tf(z,p,k);
sys = tf(num2,den2);
% Pole, zero, gain from tranfer function %
% Input Numerator & Denominator Coefficients %
num3= [2 3];
den3 = [3 5 4 1];
[z p k] = tf2zp(num3,den3) %TF form to Pole-Zero form
% CLTF from OLTF %
s = tf('s'); %'s' is a laplace variable
G1 = 2/(s*(s+3)); %Forward Path TF 1
G2 = 1/(s + 2); %Forward Path TF 2
H = 1/s; %Feedback Path TF
cltf = feedback(G1*G2, H) %CLTF

You might also like