Sheet 3
>> a=0:2:100;
>>sum(a)
ans =
2550
>>
k=0;
sum=0;
for i=0:1000
k=k+1;
sum=sum+1/2^i;
if (sum>1.995) break
end
end
k =
9
>>sum
sum =
1.9961
>>
3.1 Write a MATLAB program to add all the even
numbers from 0 to 100.
3.2 Add all the terms in the series
1 +
1
2
+
1
4
+
1
8
+ ⋯
until the sum exceeds 1.995.
Sheet 3
x=ones(1,12);
for i=3:12
x(i)=x(i-2)+x(i-1);
end
>>sequance
>>x
x =
1 1 2 3 5 8 13 21 34 55 89 144
>>
x=[70,85,90,97,50,60,71,83,91,86,77,45,67,88,64,
79,75,92,69];
A=0;
F=0;
For i=1: length(x);
if x(i)> 90
A=A+1;
elseif x(i)<= 60
F=F+1;
end
end
>>degres
>> A
A =
3.3 The Fibonacci sequence is given as
1 1 2 3 5 8 13 21 34 …
Write a MATLAB program to generate the Fibonacci
sequence up to the twelfth term.
3.4 The table below shows the final course grade and its
correspondingrelevant letter grade(a) Determine the
number of students who attained the grade of A and F.
(b) What are the mean grade and the standard deviation?
Sheet 3
2
>> F
F =
3
>>mean(x)
ans =
75.7368
>>std(x)
ans =
14.3946
>>
clear all
y=ones(1,7);
x=ones(1,7);
y(1)=2;
for i=3:7
y(i)=2*y(i-1)-y(i-2)+x(i);
end
z=y(4:7)
z =
2 4 7 11
3.5 Write a script file to evaluate y[1], y[2], y[3] and y[4]
for the difference equation:y[n]=2y[n−1]−y[n−2]+x[n]for
n ≥0. Assume that x[n]=1 for n ≥0, y[−2]=2 andy[−1]=1.
Sheet 3
clear all; close all; clc;
l=4; c=1e-6; w=200:1200;
Z=100+1j*w*l+1./(1j*w*c);
semilogy(w,abs(Z))
xlabel('angular frequency rad/sec');
ylabel('abs(z)');
zmin =
min(abs(Z))
k=find(Z==zmin);
w0 = w(k)
zmin =
100
w0 =
500
>>
3.6 The equivalent impedance of a circuit is given as
𝑍𝑍𝑒𝑒𝑒𝑒(𝑗𝑗 𝑗𝑗) = 100 + 𝑗𝑗 𝑗𝑗𝑗𝑗 +
1
𝑗𝑗 𝑗𝑗𝑗𝑗
If L = 4 H and C = 1 μF,
(a) Plot |Zeq(jw )| versus w. (b) What is the minimum impedance?
(c) With what frequency does the minimum impedance occur?
NAME: Ahmed El-morsy Abdel-hamid
Sec: 1
about me :)
THANK YOU 

Sheet 3

  • 1.
    Sheet 3 >> a=0:2:100; >>sum(a) ans= 2550 >> k=0; sum=0; for i=0:1000 k=k+1; sum=sum+1/2^i; if (sum>1.995) break end end k = 9 >>sum sum = 1.9961 >> 3.1 Write a MATLAB program to add all the even numbers from 0 to 100. 3.2 Add all the terms in the series 1 + 1 2 + 1 4 + 1 8 + ⋯ until the sum exceeds 1.995.
  • 2.
    Sheet 3 x=ones(1,12); for i=3:12 x(i)=x(i-2)+x(i-1); end >>sequance >>x x= 1 1 2 3 5 8 13 21 34 55 89 144 >> x=[70,85,90,97,50,60,71,83,91,86,77,45,67,88,64, 79,75,92,69]; A=0; F=0; For i=1: length(x); if x(i)> 90 A=A+1; elseif x(i)<= 60 F=F+1; end end >>degres >> A A = 3.3 The Fibonacci sequence is given as 1 1 2 3 5 8 13 21 34 … Write a MATLAB program to generate the Fibonacci sequence up to the twelfth term. 3.4 The table below shows the final course grade and its correspondingrelevant letter grade(a) Determine the number of students who attained the grade of A and F. (b) What are the mean grade and the standard deviation?
  • 3.
    Sheet 3 2 >> F F= 3 >>mean(x) ans = 75.7368 >>std(x) ans = 14.3946 >> clear all y=ones(1,7); x=ones(1,7); y(1)=2; for i=3:7 y(i)=2*y(i-1)-y(i-2)+x(i); end z=y(4:7) z = 2 4 7 11 3.5 Write a script file to evaluate y[1], y[2], y[3] and y[4] for the difference equation:y[n]=2y[n−1]−y[n−2]+x[n]for n ≥0. Assume that x[n]=1 for n ≥0, y[−2]=2 andy[−1]=1.
  • 4.
    Sheet 3 clear all;close all; clc; l=4; c=1e-6; w=200:1200; Z=100+1j*w*l+1./(1j*w*c); semilogy(w,abs(Z)) xlabel('angular frequency rad/sec'); ylabel('abs(z)'); zmin = min(abs(Z)) k=find(Z==zmin); w0 = w(k) zmin = 100 w0 = 500 >> 3.6 The equivalent impedance of a circuit is given as 𝑍𝑍𝑒𝑒𝑒𝑒(𝑗𝑗 𝑗𝑗) = 100 + 𝑗𝑗 𝑗𝑗𝑗𝑗 + 1 𝑗𝑗 𝑗𝑗𝑗𝑗 If L = 4 H and C = 1 μF, (a) Plot |Zeq(jw )| versus w. (b) What is the minimum impedance? (c) With what frequency does the minimum impedance occur? NAME: Ahmed El-morsy Abdel-hamid Sec: 1 about me :) THANK YOU 