Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
( 15 )
t + 0.25 ]
(b) x(t) = 5 cos[ 2(15) t - 0.5
] + 5 cos[ 2(10) t + 0.3]
Please label all plots
clearly. Please include
program listing and
plots in your solution.
Solution:
% Problem 1(a)
clear
t=0:0.01:3;
x=5*cos(2*pi*15*t+0.
25*pi);
subplot(2,1,1);
plot(t,x);
xlabel('t');
ylabel('x(t)');
title('problem 1a');
% Problem 1(b)
x=5*cos(2*pi*15*t0.5*pi) +
5*cos(2*pi*10*t+0.3*
pi);
subplot(2,1,2);
plot(t,x);
xlabel('t');
ylabel('x(t)');
title('Problem 1b');
2. Plot the following discretetime signals using MATLAB.
If you decide that the signal is
periodic, select a range for
time t that will cover at least 3
time periods.
(a) x(n) = 0.5 |n| , in the range
-5 < n < 5
(b) x(n) = 5 cos( n + 0.3),
= 1.5 .
Please label all plots clearly.
Please include program listing
and plots in your solution.
Solution:
% Problem 2(a)
clear
n=-4.9:4.9;
x=0.5.^abs(n);
subplot(2,1,1);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Problem 2a');
% Problem 2(b)
w=1.5*pi;
x=5 *cos(w*n +
0.3*pi);
subplot(2,1,2);
stem(n,x);
xlabel('n');
ylabel('x(n)');
title('Problem 2b');
% Problem 1
% Problem 2
clear
n=[0.035 0.020 0.015 0.030 0.022];
P=100000; %Principal
s=[0.0001 0.0002 0.0010 0.0007 0.0003];
borrow amount, dollars
b=[10 8 20 24 15];
i=6/100; %Annual interest h=[2 1 1.5 3 2.5];
rate
u=sqrt(s).*(b.*h./(b+2*h)).^(2/3)./n;
% n is year index
plot(n,u);
1,2,3,4,5.
% A is the annual payment
n=1:5;
i1=(1+i).^n;
F=P*i1;
table(n,F,'VariableNames
',{'n' 'F' });
clear
y = imread('ngc6543a.jpg');
imshow(y);
ymin=min(min(min(y)))
ymax=max(max(max(y)))
ysize=size(y)
number_of_pixels=ysize(1)*ysize(
2)
%%%%%%%%%
ymin=0
ymax=255
ysize=6506003
% Problem 3
% Relative error = (True value - approximate value)/True value
clear
x=5;
true = exp(-x);
% true value
% Calculation of approximate value using first series
approx1=0.0;
for i = 1:20;
ii=(-1)*(i+1);
% to create the alternating negative sign in series
approx1=approx1+ii*x^(i-1)/factorial(i-1);
true_error1= true-approx1
rel_error1=(true-approx1)/true
end;
% Calculation of approximate value using second series
approx2=0.0;
for i = 1:20;
approx2=approx2+x^(i-1)/factorial(i-1);
true_error2= true-1/approx2
rel_error2=(true-1/approx2)/true
end;
% Problem 4
clear
A=0.15;
e=0.90;
sigma=5.67e-8;
T=650;
Tl=650-20;
Tu=650+20;
Radiation_rate = A*e*sigma*T^4;
Radiation_ratel = A*e*sigma*Tl^4;
Radiation_rateu = A*e*sigma*Tu^4;
error_l=Radiation_rate- Radiation_ratel;
error_u=Radiation_rate- Radiation_rateu
'the true error will lie between',error_l,'and',error_u
Tl=650-40;
Tu=650+40;
Radiation_rate = A*e*sigma*T^4;
Radiation_ratel = A*e*sigma*Tl^4;
Radiation_rateu = A*e*sigma*Tu^4;
error_l=Radiation_rate- Radiation_ratel;
error_u=Radiation_rate- Radiation_rateu
Apolynomialfunctionisgivenby:
y(x)=x48x33.5x2+450x1001
a
Howwouldyouapproachtheproblem
of finding the roots of the function?
Create a Howmanyrootsdoyouexpect?
linearly spaced array of
b
Write a brief Matlab program to
points
determinetherootsofthefunction.
start:diffval:limit
where start is the first value in the
%Problem1
array,
clear is the difference between
diffval
P=[183.54501001];
successive
values in the array, and
roots(P)
limit
is the boundary for the last value
>>1:0.6:3
ans = 1.0000 1.6000 2.2000
2.8000
>>linspace(0, 1, 6)
ans =
0 0.2000 0.4000 0.6000 0.8000
1.0000
title('Plot of v versus t')
xlabel('Values of t')
ylabel('Values of v')
grid
hold on and hold off
subplot(m, n, p)
n = input('promptstring')
n = input('promptstring', 's')
month = input(enter month,1-12 )
day = input(enter day, 1-31 )
year = input(enter year,20xx )
today_date=[month day year]
disp(value)
%d - integer format
%e - scientific format with lowercase e
%E - scientific format with uppercase
E
%f - decidmal format
%g - the more compact of %e or %f
\n - start a new line
\t - tab
\\ - print the \ character
Thecosinefunctioncanbeevaluatedbythefollowinginfiniteseries:
cos( x) 1
a
b
x2 x4 x6
....
2! 4! 6!
Howwouldyouapproachtheproblemtoevaluatethevalueofcos(x)uptothefirst10terms.
Whatcouldyouexpectasthenumberoftermsincreases?
WriteabriefMatlabprogramtoevaluatethepercentageerror,givenby:
% Error
foravalueofx=0.5.
%Problem2
clear
x=0.5
true_value=cos(x);
approx_value=0.0;
fori=1:10;
approx_value=approx_value+x^(2*(i1))*(1)^(i1)/factorial(2*(i1));
3. Three kinds of material metal, plastic and rubber are required for production. The amounts required
to produce each component are shown in the table below:
Componen
t
1
2
3
Metal, g/component
Plastic, g/component
Rubber, g/component
15
17
19
0.25
0.33
0.42
1.0
1.2
1.6
Write a Matlab program to find how many of each component can be produced per day, if totals of 2.12,
0.0434 and 0.164 kg. of metal, plastic and rubber, respectively, are available each day.\
Let the number of units of components 1,2 and 3 be x,y and z respectively.
15x + 17y + 19z = 2120
0.25x + 0.33y + 0.42z = 43.4
1.0x + 1.2y + 1.6z = 164
[A][p] = [B]
% Problem 3
clear
a = [15 17 19;0.25 0.33 0.42;1.0 1.2 1.6];
b=[2120;43.4;164];
p1=inv(a)*b;
p2=a\b;
p3=linsolve(a,b);
y = @(x) x^4*(sin(x)
+4*(cos(x))^2)
x1 =fzero(y,1)
(x
3 y 2 xy3 )dxdy
2 0
% Problem 4a
clear
N=100;
dx=(4-0)/N;
dy=(2-(-2))/N;
for i=1:N;
x(i)=0+(i-1)*dx;
for j=1:N;
y(j)=-2+(j-1)*dy;
z(i,j)=x(i)^2-3*y(j)^2+x(i)*y(j)^3;
end;
end;
I1=trapz(z,1);
I2=trapz(I1);
I=I2*dx*dy;
I=
1.1269e+004
4b.
Write a Matlab program to calculate
the differential:
(x
1
1
) dx
x2
x=1:0.01:2;
y=x+(1./x.^2);
I=trapz(x,y)
2. (a) Write a Matlab program to
calculate the integral:
2
I [ x 2 x sin( x )]dx
1