A substance is said to be subject to exponential decay if it

A substance is said to be subject to exponential decay if it decreases at a rate proportional to its value. Symbolically, this can be expressed as the following differential equation, where N is the quantity and L (lambda) is a positive number called the decay constant: dN/dt = -LN The solution to this equation is: N(t) = N(0)e^Lt Here N(t) is the quantity at integer time t, and N(0) is the (initial) quantity (at time t=0) and L is the decay constant. Larger decay constants make the quantity vanish much more rapidly. Use this fact to create a test table and then write the function called exp Decay (with three arguments N(0), L, t and one return value N(t)) to solve the problem. Use your test table to test your function. Show how to call your function and save the returned value in a variable named future Quantity. Design will be done in lecture or lab.

Solution

The Matlab function expDecay.m

function Nt = expDecay(N0,L,t)
% this function compute the quantity at time t using the
% numerical solution of differentil equation given in the
% problem using the matlab ode solver ode45
[~,N] = ode45(@(t,x) -L*x,[0 t],N0);
Nt= N(end);
end

The Matlab function expDecay_exact.m

function Nt = expDecay_exact(N0,L,t)
% this function compute the quantity at time t using the
% exact solution of differential equation given in the
% problem
Nt = N0*exp(-L*t);
end

The Matlab script test_case_of_decay.m

N0 = [10000 5500 9999 500]; % The intial values of N, N(0) for 4 test case
L = [0.5 1 0.9 .3]; % four decay constants for four test case
t = [3 1 2 .5]; % final time
% Edit the above data for variaous test problems
for k = 1:length(N0)
    futureQuantituy = expDecay(N0(k),L(k),t(k));
fprintf(\'N0=%f, L=%f, t=%f, (ode45)Nt=%f, (exact)Nt=%f\ \',N0(k),L(k),t(k),futureQuantituy,expDecay_exact(N0(k),L(k),t(k)));
end

OUTPUT

>> test_case_of_dacay
N0=10000.000000, L=0.500000, t=3.000000, (ode45)Nt=2231.301692, (exact)Nt=2231.301601
N0=5500.000000, L=1.000000, t=1.000000, (ode45)Nt=2023.336933, (exact)Nt=2023.336926
N0=9999.000000, L=0.900000, t=2.000000, (ode45)Nt=1652.823794, (exact)Nt=1652.823583
N0=500.000000, L=0.300000, t=0.500000, (ode45)Nt=430.353988, (exact)Nt=430.353988
>>

 A substance is said to be subject to exponential decay if it decreases at a rate proportional to its value. Symbolically, this can be expressed as the followin

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site