Sie sind auf Seite 1von 29

MAT LAB

MATLAB is a programming language developed by MathWorks. It started out as a


matrix programming language where linear algebra programming was simple
Write a program to plot a sin graph for the given range

Aim:

x=0:0.05:5;
y=sin(x.^2);
plot(x,y);

Result:
WRITE A PROGRAM TO PLOT A STEM GRAPH FOR THE GIVEN RANGE OF VALUES

Aim:

x = 0:0.1:4;
y = sin(x.^2).*exp(-x);
stem(x,y)

Result
PROGRAM FOR GRID IN A FUNCTION WITH GRAPH

Aim:

Figure
Plot (x , y )0
xlabel (‘X’)
ylabel (‘ y= f (x)’)
grid on
title (‘ plot of function f1(x)’)
legend (‘f1(x)’)
axis [ -2 4 2 -12]

Result:
Write a program to find out the various matrix operations

Aim:

a=[3 2 4 5;5 6 7 8;4 6 8 3; 3 9 7 5];


b=[6 6 9 7;8 5 3 2; 6 2 6 2; 6 4 1 2]
b=
6 6 9 7
8 5 3 2
6 2 6 2
6 4 1 2
c=inv(a)
c=
-2.0704 1.7465 0.2958 -0.9014
-0.7042 0.4648 -0.0423 -0.0141
1.3099 -1.0845 0.0986 0.3662
0.6761 -0.3662 -0.2394 0.2535
d=inv(b)
d=
-0.1169 -0.3766 0.2792 0.5065
0.1299 0.9740 -0.5325 -0.8961
0.0519 0.3896 -0.0130 -0.5584
0.0649 -1.0130 0.2338 1.0519
x=inv(a)*b
x=
-2.0845 -6.7042 -12.5211 -12.2113
-0.8451 -2.0423 -5.2113 -4.1127
1.9718 4.0986 9.4930 7.9296
1.2113 2.7606 3.8028 4.0282
y=a*inv(b)
y=
0.4416 -2.6883 0.8896 2.7532
1.0779 -1.4156 -0.0195 1.6623
0.9221 4.4156 -1.4805 -4.6623
1.5065 5.2987 -2.8766 -5.1948

z=inv(a)*inv(b)
z=
0.4256 3.5092 -1.7226 -3.7271
0.1396 0.7157 -0.4469 -0.7644
-0.2650 -1.8822 1.0275 1.9654
-0.1226 -0.9614 0.4461 1.0710
m=a+b
m=

9 8 13 12
13 11 10 10
10 8 14 5
9 13 8 7
Write a program to plot a graph for two functions

Aim:

a=0:15:90
a=
0 15 30 45 60 75 90
f1=2.*sind(a).*cosd(a)
f1 =
0 0.5000 0.8660 1.0000 0.8660 0.5000 0
f2=exp(f1)
f2 =
1.0000 1.6487 2.3774 2.7183 2.3774 1.6487 1.0000
hold on
plot(f1)
plot(f2)

Result:
WRITE A PROGRAM FOR THE GIVEN FUNCTION AND PLOT THE GRAPH
Aim:

F2 = (3t2 ) * sin (4t+4)

X= [ -1 0 1 2 ]
Y=3*x+4;
figure
plot (x,y)
xlabel ( ’x’ )
ylabel (‘y =f(x) ‘.
grid on
title ( ‘plot of function f1 (x)’)
legend (‘f1(x)’)
axis ([-2 4 -2 12)]
t = [0: .01 :5]
gt = 3 * t ^2;
ht = sin (4* t + 4)
f2 = gt .* ht;
figure
plot (t, f2, ‘rx’)
Result:
Write a program for sin and cos functions and plot both the functions on the same
graph

Aim:

x = 0: 2*pi/40:
2*pi;
y = sin(x);
plot(x,y,‘ro’)
hold on
y = cos(x);
plot(x,y,‘b+’)
legend(‘sin’, ‘cos’)
title(‘sin and cos on one graph’)

Result:
Write a program to find the area of a circle using if loop

radius= input('Enter the radius');


if radius<=0
fprintf('invalid value');
else
area=pi*radius.^2;
fprintf('the radius of the circle is %.2f,',radius)
fprintf('the area of the circle is %.2f/n',area)
end

Result
Enter the radius4
the radius of the circle is 4.00,the area of the circle is 50.27/n
Enter the radius0
invalid value
Write a program to find out the stiffness matrix of a bar element shown below.
Take E1= E3 =90 GPa, E2 =210 GPa A1=A3=1200mm2, A2=1400 mm2, L1=L2=L3=250MM

1 2 1
a1=1200;
Aim:

a2=1400;
e1=90*10^-5;
e2=210*10^-5;
l=250;
k1=(a1*e1/l)*[1 -1 0 0;-1 1 0 0;0 0 0 0;0 0 0 0]
k1 =
0.0043 -0.0043 0 0
-0.0043 0.0043 0 0
0 0 0 0
0 0 0 0

k2=(a2*e2/l)*[0 0 0 0;0 1 -1 0;0 -1 1 0;0 0 0 0]


k2 =
0 0 0 0
0 0.0118 -0.0118 0
0 -0.0118 0.0118 0
0 0 0 0

k3=(a1*e1/l)*[0 0 0 0;0 0 0 0;0 0 1 -1;0 0 -1 1]

k3 =
0 0 0 0
0 0 0 0
0 0 0.0043 -0.0043
0 0 -0.0043 0.0043

k=k1+k2+k3
k=

0.0043 -0.0043 0 0
-0.0043 0.0161 -0.0118 0
0 -0.0118 0.0161 -0.0043
0 0 -0.0043 0.0043
Write a program to find the following.
8 −2 0 2
A = −2 4 −3 D= −1
0 −3 3 3
Find
a) I- DDT
b) Det (A)
c) X=AD

Aim:

a=[8 -2 0; -2 4 -3; 0 -3 3];


d=[2;-1;3]
d=
2
-1
3

i=[1 0 0; 0 1 0; 0 0 1];
x=i-d*transpose(d)
x=
-3 2 -6
2 0 3
-6 3 -8
inv(a)
ans =
0.2500 0.5000 0.5000
0.5000 2.0000 2.0000
0.5000 2.0000 2.3333
y=a*d
y=
18
-17
12
y=a*transpose(a)

y=
68 -24 6
-24 29 -21
6 -21 18
z=inv(a)*d
z=
1.5000
5.0000
6.0000
Write a program to plot graphs of various trigonometric functions

Aim:

a=0:15:90;
>> b=0:15:90;
>> x=tan(a);
>> y=tan(b);
p=x+y
p=
0 -1.7120 -12.8107 3.2396 0.6401 -0.8414 -3.9904
>> q=1-x.*y
q=
1.0000 0.2673 -40.0283 -1.6237 0.8976 0.8230 -2.9808
>> m=p/q
m=
0.3210
>> m=p./q
m=
0 -6.4053 0.3200 -1.9952 0.7131 -1.0223 1.3387
Result:

>> plot(m)
Write a program to find the displacement, final velocity and displacement in nth second
of a particle.
Let initial velocity be 10m/s, acceleration be 22m/sec2 time taken be 18 sec. find
displacement in every 3rd sec

Aim:

u=10;
>> a=22;
>> t=18;
>> v=u+a*t;
s=u*t+0.5*a*t^2
s=
3744
>> v=u+a*t
v=
406
>> t1=1:3:18;
>> s1=u+(a/2).*(2*t1-1)
s1 =
21 87 153 219 285 351
s=u.*t1+0.5.*a.*t1.^2
s=
21 216 609 1200 1989 2976
>> plot(s)
INTRODUCTION TO PROGRAMMABLE LOGIC CONTROLLERS
A programmable logic controller (PLC) is a small, modular solid state computer with
customized instructions for performing a particular task. PLCs, which are used in
industrial control systems (ICS) for a wide variety of industries, have largely replaced
mechanical relays, drum sequencers and cam timers.
PLCs are useful tools for repeatable processes because they have no mechanical parts
and they can gather information. Each central processor unit (CPU) continually loops
through an input scan, program scan, output scan and housekeeping mode, repetitively
performing a single task while monitoring conditions. The information the controller
gathers can be used as feedback to guide needed changes and improvements to
processes, some of which can be performed automatically according to the device’s
coding.
PLCs take up less space, perform more complex tasks and are more customizable than
the mechanical technologies they have replaced. They are known for their ability to
operate continuously without maintenance and have had a great impact on digitizing a
great many industries, particularly manufacturing. The first PLC, for example, was
invented by Dick Morley in 1969 for General Motors and performed uninterrupted for
20 years before being retired.
Five programming languages are used to code PLCs, as specified by International
Electrotechnical Commission (IEC) 61131. They are Ladder Logic, Function Block
Diagram (FBD), Structured Text (ST), Instruction List (IL) and Sequential Function Chart
(SFC). Should significant code changes be required and the PLC's memory is embedded,
the controller can be recoded in place. When the PLC's memory is not embedded on the
circuit board and significant code changes are required, the memory can be removed
from an exterior slot on the PLC and replaced without requiring the assistance of a
programmer on site. 
PLC Program to Implement Various Logic Gates

Problem Description
Implementation of various Logic Gates AND, OR, NOT, NOR, NAND, EX-OR and EX-NOR
in PLC using Ladder Diagram programming language.
Problem Solution

 Assuming that all the gates comprise two inputs and NOT Gate has only one
input, Logic Gates can be well implemented in PLC using Ladder Diagram
programming language as shown in “Program” section.
 To implement Examine if closed, Normally Open contact is used and to
implement Examine if open, Normally Closed contact is used.
 These contacts is said to work as relay contacts.
 In Normally Open / XIC contact, when logic 1, or in other words, when logic high
is provided, the contact closes allowing current to pass through the circuit.
 And in Normally Closed / XIO contact, when logic 1 is not present, or in other
words, when logic 0 is present, it allows current to pass through the circuit. But
when logic 1 is present in case of XIO, the contact opens inhibiting current to pass
through the circuit.
 By simply using these logics, all Logic Gates can be well implemented using
Ladder Diagram programming language.

Symbol of Logic Gates

PLC Program
Here is PLC program to implement various logic gates, along with program explanation
and run time test cases.
AND

 By connecting Normally Open / XIC contacts in series, AND gate can be


implemented.
 When both inputs are set to 1, then and then only output goes high.

OR

 By connecting Normally Open / XIC contacts in parallel, OR Gate can be


implemented.
 When either input is set to high, output goes high.

NOT

 By using just one Normally Closed / XIO contact, NOT Logic Gate can be
implemented.
 Inverted state of input is obtained as an output.

NOR

 By connecting Normally Closed / XIO contacts in series, NOR Logic Gate can be
implemented.
 If both inputs are Reset to 0, output goes High otherwise remains in Low state.
 Or by inverting output of a OR Gate, that is by using output of OR Gate as an input
of NOT Gate, NOR Gate can be implemented.
NAND

 By connecting Normally Closed contacts in parallel to each other, NAND Gate can
be implemented.
 Or by simply inverting output of AND gate, NAND Gate can be implemented.

EX-OR

 By connecting XIC and XIO in series with parallel to XIO and XIC in series as
shown in diagram above, EX-OR Gate can be implemented.
 When both inputs are identical, output is 0. Output is high when A ≠ B.
 Note here that XIC of first series contacts and XIO of second series contacts must
be given same address and similarly for the other two.

EX-NOR

 By connecting two XIO contacts in series with parallel to two XIC contacts in
series, EX-NOR gate can be implemented.
 When both inputs are identical A=B=O or A=B=1, output goes high.
 It implies same here as in EX-OR gate that address must be given same.
 – By inverting output of EX-OR gate, implementation of EX-NOR can be
accomplished.

Runtime Test Cases


Inputs Outputs
A B AND OR NOR NAND EX-OR EX-NOR
0 0 0 0 1 1 0 1
0 1 0 1 0 1 1 0
1 0 0 1 0 1 1 0
1 1 1 1 0 0 0 1
 
Inputs Output
A NOT
0 1
1 0

Das könnte Ihnen auch gefallen