Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write all parts of the lab in an R script. When you have completed the lab, submit your R script with functions and an organized
Write all parts of the lab in an R script. When you have completed the lab, submit your R script with functions and an organized report in a Word document to Harvey. Color code your output in the Word document, include relevant code, and separate your responses for each question separately, as opposed to pasting all of the output at the end of the Word doc. 1. Consider the forward approximation to the derivative at x of f. f(x)=hf(x+h)f(x). Write a program that approximate the derivative of f(x)=sin(x) at x=p i for values of h from 10-1 down to 10-20. For each value of h compute the error given the exact derivative is cos(pi). Use the absolute value of the difference for the error. Plot the error vs. h on a log scale. Explain the behavior of the error for large and small h. What value is best for h ? Repeat for the central difference approximation. 2- a) implement the fourth order Runge-Kutta method equation for solving the initial value problem dtdy=f(t,y). This is very similar to the Euler method code we did in class. k1=f(ti,yi) k2=f(ti+21h,yi+21k1h) k3=f(ti+21h,yi+21k2h) k4=f(ti+h,yi+k3h)yi+1=yi+6h(k1+2k2+2k3+k4) b) Use your Euler and RK code to numerically solve the decay ode dtdy=ky from t=0 to 100 with step size h=10. Let k=.03 and y(0)=100. Compare the Euler and RK error relative to the exact solution for each t. 3 - Use pracma library function ode 45 to solve the decay model numerically for y(t) from t=0 to 10,000 years with k=1.21e4/yr and initial condition y0=10,000. Note: The solution outputs of ode45 are always t and y (e.g., decay.sol\$t, decay.sol\$y) regardless of the variable name you used to define the ode model. By inspecting the plot (or by exact calculation), what is the approximate half-life for the decaying system? The half-life is the time it takes for the population to decrease by half. Note: As a guide, the command abline (h=y0/2) will plot a horizontal line at y0 on top of an existing plot. You can use v in abline (v=vertical_guess) to see if you are close to the half-life time. 4. Use ode 45 to solve the following predator-prey model numerically for pred(t) and prey(t). dtdprey=k1preypred+k2preydtdpred=k3preypredk4pred a.) Use model parameters k1=.01,k2=.1,k3=.001, and k4=.05 and initial conditions prey(0)=50 and pred(0)=15. Solve the system from t=0 to 200 . After you solve the coupled system (pp.sol or whatever name you decide), use the following code to plot the two populations. b) Use your Euler and RK code to solve the system with h=10. Show a plot comparing the Prey solutions with ode45. c.) Solve the system with ode 45 changing k3 to .02. What happens to the system? What value of k4 can counteract this? 5. Use ode 45 to solve the following SIR (Susceptible-Infectious-Recovered) model numerically for S(t), I(t), and R(t) from t=0 to 20 . dtdS=aSIdtdI=aSIbIdtdR=bI a) Use model parameters a=.5 and b=1 and initial conditions S(0)=.9,I(0)=.1, and R(0)=0. Solve the system from time 0 to 20 . Show how you set up the model for ode45. Use the previous ggplot code to plot the S I R solutions. b) Repeat a.) with a=3. Describe/compare what happens to the infected group (I) when you change a from . 5 to 3 . 6. Consider the following multi-step reaction mechanism for the decomposition of dinitrogen pentoxygen into nitrogen dioxide and molecular oxygen (2N2O54NO2+O2) : N2O5NO2+NO3AB+D Creates product and intermediate NO2+NO3N2O5B+DA Reverses first reaction NO2+NO3NO+O2+NO2B+DC+C+B Creates other product and another intermed NO+NO32NO2E+D2B The reaction 2N2O54NO2+O2, with reactant A=N2O5 and products B=NO2 and C=O2, can be written as a coupled system of differential equations: dtdA=k1A+k2BDdtdB=k1Ak2BD+2k4DEdtdC=k3BDdtdD=k1Ak2BDk3BDk4DEdtdE=k3BDk4DE where D=NO3 and E=NO are the hypothesized intermediates. a. Use ode45 to solve the rate equations as a function of time for all reactants, intermediates and products. Choose k1=1.0,k2=0.5,k3=0.2, and k4=1.5. Let the initial concentration of [N2O5]0=1 and all other initial concentrations be zero. Plot and label the concentrations versus time from 0 to 10 seconds. b. Notice that the intermediate species nitric oxide NO (E variable) appears to be increasing as time goes to infinity for the given model and parameters. We want dE/dt0 for the steady state (large time). Try to make the intermediate species go to zero by increasing the parameter k4 and then by modifying the model itself. Why is setting dE/dt=0 in the ODE not a good idea
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started