Question: Modify the program to find a numerical solution for the speed as a function of time. Create a figure that shows the speed as a
Modify the program to find a numerical solution for the speed as a function of time. Create a figure that shows the speed as a function of time and the exact terminal velocity as a horizontal line. Please use a time range that brings the actual speed to within a few percent of the terminal velocity.
matlab code displayed below:
tau = 1.0; y0 = 2.0; t0 = 0.0; tf = 3.0; Nt = 101; % number of discrete time values tt = linspace(t0,tf,Nt); % row vector of Nt times between t0 and tf delt = (tf-t0)/(Nt-1); % time increment
% initialize solution to zero yeu = zeros(1,Nt); % number of particles from Euler method yeu(1) = y0 % Calculate numerical solution to dy/dt = -y/tau for ii = 1:Nt-1 % loop over time steps dydt = -yeu(ii)/tau; yeu(ii+1) = yeu(ii) + dydt*delt; % Euler method end
% for comparison, calculate the exact solution yexact = y0*exp(-tt/tau); figure(1); clf; plot(tt,yeu,'b-',tt,yexact,'r--','LineWidth',2) legend(['Euler, \Delta t = ',num2str(delt),' s'],'exact') xlabel('t/s') ylabel('N/mol') title(['Nuclear decay with \tau = ',num2str(tau),' s and N_0 = ',... num2str(y0),' mol'])
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
