% MAGANGCONG, Rania-Raihan M.
% CHE160-UuVv
% Solve Prob. 2.1 using the MATLAB laplace command.
% (a) sin((2*t)+(pi/4))
syms t s
f_a=sin((2*t)+(pi/4));
F_a=laplace(f_a,t,s);
disp('Laplace of sin((2*t)+(pi/4)):');
Laplace of sin((2*t)+(pi/4)):
disp(F_a);
% (b) (exp(-t))*cos(2*t)
syms t s
f_b=(exp(-t))*cos(2*t);
F_b=laplace(f_b,t,s);
disp('Laplace of (exp(-t))*cos(2*t)');
Laplace of (exp(-t))*cos(2*t)
disp(F_b);
% (c) sinh(k*t)
syms t k s
f_c=sinh(k*t);
F_c=laplace(f_c,t,s);
disp('Laplace of (sinh(k*t)');
Laplace of (sinh(k*t)
disp(F_c);
% Solve Prob. 2.2 using the MATLAB ilaplace command.
% (A) 3/s
syms t s
F_A=3/s;
f_A=ilaplace(F_A,s,t);
disp('Inverse Laplace of 3/s:');
1
Inverse Laplace of 3/s:
disp(f_A);
% (B) 3/(s+2)
syms t s
F_B=3/(s+2);
f_B=ilaplace(F_B,s,t);
disp('Inverse Laplace of 3/(s+2):');
Inverse Laplace of 3/(s+2):
disp(f_B);
% (C) 3/((s+2)^2)
syms t s
F_C=3/((s+2)^2);
f_C=ilaplace(F_C,s,t);
disp('Inverse Laplace of 3/((s+2)^2):');
Inverse Laplace of 3/((s+2)^2):
disp(f_C);
% (D) 3/(s^3)
syms t s
F_D=3/(s^3);
f_D=ilaplace(F_D,s,t);
disp('Inverse Laplace of 3/(s^3):');
Inverse Laplace of 3/(s^3):
disp(f_D);
% (E) (1/2)/((s^2)+9)
syms t s
F_E=(1/2)/((s^2)+9);
f_E=ilaplace(F_E,s,t);
disp('Inverse Laplace of (1/2)/((s^2)+9):');
Inverse Laplace of (1/2)/((s^2)+9):
disp(f_E);
2
% (F) 3/((s^2)+(4*s)+8)
syms t s
F_F=3/((s^2)+(4*s)+8);
f_F=ilaplace(F_F,s,t);
disp('Inverse Laplace of 3/((s^2)+(4*s)+8):');
Inverse Laplace of 3/((s^2)+(4*s)+8):
disp(f_F);
% (G) (s+4)/((s^2)+(4*s)+8)
syms t s
F_G=(s+4)/((s^2)+(4*s)+8);
f_G=ilaplace(F_G,s,t);
disp('Inverse Laplace of (s+4)/((s^2)+(4*s)+8):');
Inverse Laplace of (s+4)/((s^2)+(4*s)+8):
disp(f_G);
% (H) 1/((s+2)^2)
syms t s
F_H=1/((s+2)^2);
f_H=ilaplace(F_H,s,t);
disp('Inverse Laplace of 1/((s+2)^2):');
Inverse Laplace of 1/((s+2)^2):
disp(f_H);
% Solve Prob. 2.3 using the MATLAB dsolve command, and then use ezplot to
graph the solutions.
syms x(t) u(t)
u(t) = heaviside(t);
% (a)
eqn_a=diff(x,t,2)+4*diff(x,t)+3*x==u(t);
Dy=diff(x,t)
Dy(t) =
3
cond_a=[x(0)==0, Dy(0)==0];
xt_a=dsolve(eqn_a, cond_a);
disp('x(t)=');
x(t)=
disp(xt_a);
figure
ezplot(xt_a, [0, 10])
title('t vs xt_a');
grid on
xlabel('t');
ylabel('xt_a');
% (b)
eqn_b=diff(x,t,2)+2*diff(x,t)+x==u(t);
Dy=diff(x,t)
Dy(t) =
cond_b=[x(0)==1, Dy(0)==1];
xt_b=dsolve(eqn_b, cond_b);
4
disp('x(t)=');
x(t)=
disp(xt_b);
figure
ezplot(xt_b, [0, 10])
title('t vs xt_b');
grid on
xlabel('t');
ylabel('xt_b');
% (c)
eqn_c=diff(x,t,2)+2*diff(x,t)+x==u(t);
cond_c=[x(0)==0, Dy(0)==0];
Dy=diff(x,t);
xt_c=dsolve(eqn_c, cond_c);
disp('x(t)=');
x(t)=
disp(xt_c);
figure
5
ezplot(xt_c, [0,10]);
title('t vs xt_c');
grid on
xlabel('t');
ylabel('xt_c');
% 2.7 Use the MATLAB dsolve command to solve the differential equations that
we developed
% for the mass and energy balances for the chemical mixing scenario, and
then use ezplot to
% graph the solutions. Compare the results with those presented in the text.
% For mass balance:
syms C(t) tau
tau_val=5;
massbal=tau_val*diff(C,t)+C==2;
cond_mb=[C(0)==3];
ode_mb=dsolve(massbal, cond_mb);
disp('Mass Balance ODE:');
Mass Balance ODE:
disp(ode_mb);
figure
ezplot(ode_mb, [0,30]);
title('Time vs Concentration');
6
grid on
xlabel('Time (mins)')
ylabel(char(ode_mb));
% For Energy Balance:
syms T(t)
Q_val=1.05*(10^6);
d_val=1000;
v3_val=30;
Cp_val=1;
enerbal=tau_val*diff(T,t)+T==35+((1/((Cp_val)*(d_val)*(v3_val)))*Q_val);
cond_eb=[T(0)==80];
ode_eb=dsolve(enerbal,cond_eb);
disp('Energy Balance ODE:');
Energy Balance ODE:
disp(ode_eb);
figure
ezplot(ode_eb, [0,30]);
title('Time vs Temperature');
grid on
xlabel('Time (mins)')
ylabel(char(ode_eb));
7
% 2.8 Use the MATLAB ilaplace command to invert Eqs. (2.10) and (2.11), and
then use
% ezplot to graph the solutions. Compare the results with those presented in
the text.
% Inverse Laplace of Equation 2.10
F_e1=(2/((s)*((5*s)+1)))+(15/((5*s)+1));
f_e1=ilaplace(F_e1, s, t);
disp('Inverse Laplace of Equation 2.10')
Inverse Laplace of Equation 2.10
disp(f_e1);
figure
ezplot(f_e1,[0,30]);
title('Time vs Concentration');
grid on
xlabel('Time (mins)')
ylabel(char(f_e1));
8
% Inverse Laplace of Equation 2.1
F_e2=(70/((s)*((5*s)+1)))+(400/((5*s)+1));
f_e2=ilaplace(F_e2, s, t);
disp('Inverse Laplace of Equation 2.11')
Inverse Laplace of Equation 2.11
disp(f_e2);
figure
ezplot(f_e2,[0,30]);
title('Time vs Temperature');
grid on
xlabel('Time (mins)')
ylabel(char(f_e2));
9
10