Write a MATLAB code to solve the following difference equations by z-transform and display the solutions by stem plots:
2) Suppose that the number of bacteria in a colony doubles every hour. If a colony begins with five bacteria, how many will be present in n hours?
close all,
clear all,
clc,
a=5;
syms n z
f = a*2^(n-1);
disp(['Z-Transform: f = ',32,num2str(a),'*2^(n-1):']);
fZT = ztrans(f)
disp(['No. of bacteria at the end of n hours = ']);
IZT = iztrans(fZT)
Grwoth=[];
for r=1:10
n=r;
Growth(r) = 5/2*2^n;
end
stem(Growth);
title('Stem Plot: Bacteria Growth','FontSize',20);
xlabel('--- t (Hours) --->');
ylabel('--- Growth --->');
grid on,
Comments
Leave a comment