PRACTICAL MATLAB® FOR ENGINEERS PRACTICAL MATLAB

(sharon) #1

188 Practical MATLAB® Applications for Engineers


ANALYTICAL Solution

The loop differential equation is given by

V
di t
dt
1 ^20 Vf^2 it ort^0

()
()

with

A and ii() 0 ( ) A
10
2
5
20
2
  10

Assuming a solution for i(t) of the form i(t) = A + Be−t/τ, where τ = L/R = 0.5 s, and by
using the initial and fi nal current conditions, the constants A and B can be evaluated.
By following this process the current is then i(t) = 10 − 5 e−^2 t A, and the corresponding
voltages are vR(t) = 20 − 10 e−^2 t V and vL(t) = 10e−^2 t V, for t ≥ 0.
MATLAB Solution
% Script file: RC _ IC
syms t;
% symbolic solution
it _ 1 = dsolve(‘Dy+2*y=20’,’y(0)=5’,’t’);
disp(‘*****************************************’);
figure(1)
subplot(3,1,1);
ezplot (it _ 1,[0 2]);ylabel(‘i(t) in amps’);
title(‘plots of: [i(t), vr(t) and vL(t)] vs t’);
subplot(3,1,2);
vtr _ 1 = it _ 1*2;
ezplot(vtr _ 1,[0 2]);ylabel(‘vr(t)’);title(‘ ‘);
subplot (3,1,3);
vl_1 = 20-vtr_1;
ezplot (vl _ 1,[0 2]);ylabel(‘vL(t)’);title(‘ ‘);
xlabel (‘time in sec.’);
disp(‘**********R E S U L T S ****************’);
disp(‘*****************************************’);
disp(‘The i(t) for t >0 is:’);
it _ 1
disp(‘The voltage across R=2 ohms is :’)
vtr _ 1
disp(‘The voltage across L=1 henry is :’)
vl _ 1
disp(‘********Verify solution******************’);
echo on
disp(‘******************************************’)
verify = diff(it _ 1,t)+2*it _ 1
echo off
% numerical solution
clear;
% solution using ode45
t0 = 0;R=2;
tf = 2;
ts = [t0 tf];
i0 = 5; % initil cond.
t =linspace(0,2,100);
[t,it] = ode45(‘f’,ts,i0);
Free download pdf