Experiment 2
Experiment 2
1) if ... end
if expression (condition)
statements
end
-----------------------
Here are some examples based on the familiar quadratic formula.
a=input('enter value of a=');
b=input('enter value of b=');
c=input('enter value of c=');
1.
discr = b*b - 4*a*c;
if discr < 0
disp('Warning: discriminant is negative, roots are imaginary');
end
2.
discr = b*b - 4*a*c;
if discr < 0
disp('Warning: discriminant is negative, roots are imaginary');
else
University of Ninevah
College of Electronics Engineering
Electronic Engineering Department
2 nd Year
In the for ... end loop, the execution of a command is repeated at a fixed and predeter-
mined number of times. The syntax is
University of Ninevah
College of Electronics Engineering
Electronic Engineering Department
2 nd Year
Usually, expression is a vector of the form i:s:j. A simple example of for loop is
for ii=1:5
x=ii*ii
end
for example
n=5
a=eye(n)
for j=2: n
for i =1: j-1
a(i,j)=i/j
a(j,i)=i/j
end
end
Experiments
Q1) find and plot the signal x(t) for the system shown
x(t)= 4 t + 1 if t > 0
=t-5 if t< -1
Q2) find and plot the signal x(n) for the system shown:
x(t)= 2 n+ 1 n= 0
= n- 3 n< -1
= n+ 3 -3<n<2
= 0.5 n + n 5< n