Review the Predator Prey notes. This assignment is to solve the Lotka-Volterra equations using the *backward*...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Review the Predator Prey notes. This assignment is to solve the Lotka-Volterra equations using the *backward* Euler method. Follow the procedure I used in class for the FHN equations. You may use the backward EulerND and newtonND examples from class. You will need to write a function called IvBE that will be passed through backward EulerND and into newtonND to evaluate the function value vector and Jacobian matrix needed by newtonND. It will be analogous to fhnBE from class. Also write a script that sets parameter values, timestep increment, etc., then calls backward EulerND and plots the solution. It would be wise to first solve the system using rk4 or eulerND to be sure you are getting a correct solution from backward EulerND. Call your script runLV. Use a time step of 0.001. Set the initial condition for chipmunk population, c, to 1.0 and the initial kitty population, k, to 0.1. At first, use the parameters: alpha = 1 beta = 10 delta=1 gamma=1 This is actually a fixed point of the system of ODEs, so the two populations will stay perfectly balanced at the initial values. Next, make the cats less hungry by reducing beta, then more hungry by increasing beta. Observe what happens to the two populations in the two cases. Then set beta back to 10 and make the cats longer lived by increasing gamma to 10. Again, observe what happens to the populations. Feel free to play with other parameter combinations. Upload runLV.m, LVBE.m and a plot of your solution for the parameters alpha=1, beta=15, delta=1, gamma=1. Your code must be appropriately commented and indented. function [F, J] = fhnBE (Unp1, paramsNewton) % function [F, J] = fhnBE (Unp1, params Newton) % % Used to solve the FHN system of ODEs using the multidimensional backward % Euler method. It is called by newtonND which is called by % backward EulerND. The system is % % % du/dt = c1*u* (u-a)*(1-u) - c2*u*v + Ileak. dv/dt b* (u-d*v) % % Applying the backward Euler method produces two nonlinear expressions % that must be solved in each timestep. % % let unp1 be u(n+1), the value of u in the next timestep we are trying to % find. similarly, vnp1 is v(n+1). un and vn are the known values of u and % v in the current timestep, u(n) and v(n). The two expressions are: % % f(unp1, vnp1) = un + (c1* unp1* (unp1-a)*(1-unp1) - c2unp1*vnp1 + Il )*dt unp1 % g(unp1, vnp1) = vn + b* (unp1 - d*vnp1) *dt % % The input vector Unp1 contains unp1 and vnp1. paramsNewton contains the % constants in the ODE as well as un, vn, and dt. It was packed up by % backward Euler ND and passed into newtonND, which passed it here. The % function returns F, which is f and g stacked into a column vector, and J, % the Jacobian matrix of F % unpack current estimates for unp1 and vnp1. The very first time % newton ND calls this function, these will be un and vn. newton ND will % improve these estimates iteratively until it finds values that when % plugged into f and g make both expressions 0. unp1 = Unp1 (1); vnp1 = Unp1(2); % unpack the constants in the ODE. These were passed into % backward Euler ND as params. a = params Newton (1); b = paramsNewton (2); c1= paramsNewton (3); c2 paramsNewton (4); d = paramsNewton (5); Il = paramsNewton (6); % unpack un and vn un vn params Newton (7); paramsNewton (8); % unpack t(n+1). Time does not appear in the RHSs of the FHN system, so % we don't need it. tnp1 = params Newton (9); %unused % unpack dt dt = paramsNewton (10); % we now have all the info we need to evaluate f and g. f = un + (c1*unp1* (unp1-a)*(1-unp1) - c2*unp1*vnp1 +Il) *dt g = vn + b* (unp1-d*vnp1) *dt - vnp1; F = [f;g]; % stack into column vector end % compute the elements of the Jacobian matrix. dfdunp1 is the % derivative of f with respect to unp1 - dfdunp1 c1*dt* ( -unp1* (unp1-a) + unp1*(1-unp1) + (unp1-a)*(1-unp1) ) - c2*dt*vnp1-1; % the other components are simpler... dfdvnp1 = -c2*dt*unp1; dgdunp1 b*dt; dgdvnp1 = -b*d*dt - 1; = % deriv of f wrt vnp1 % deriv of g wrt unp1 % deriv of g wrt vnp1 J = [dfdunp1 dfdvnp1; dgdunp1 dgdvnp1]; unp1; % assemble Jacobian. derivs of f in top row, of g in second row. Look % at the nonlinear 2D notes to see see why F and J are structured this % way. function [U, t] = backward Euler ND (UO, dt, tend, params, fcn) % function [U, t] = backward Euler ND (U0, dt, tend, params, fcn) % % Solves a *system* of ODEs using the backward Euler method. The calling % sequence is simlar to all our other ODE integrating functions. This uses % the same idea as backward Euler for a *single* ODE, but taking a backward % Euler timestep for a *system* of ODEs results in a *system* of nonlinear % algebraic expressions whose root must be found in each timestep. We use % the multidimensional Newton method to do this. For the FHN example, fcn % will be a handle to fhnBE, which evaluates these expressions % initialize solution array U and time vector t as before. U(1, :) = U0; t = 0:dt: tend; U(length(t), :) = 0; % timestep loop for n-1: length(t)-1 end end % Our initial guess for the solution U at timestep n+1 is just the % solution at timestep n. NewtonND expects its intitial guess for % the root to be in a column vector, so we transpose. guess = U(n, :)'; tol=1.e-8; % convergence tolerance for Newton ND % The params vector passed into this function contains the % constants in the ODEs. For the FHN system, this is a, b, c1, c2, d, % and Ileak. fcn, the function that evaluates the system of % nonlinear expressions we are finding the root to (and its % Jacobian matrix) also needs some other information: the current % U, sometimes t(n+1) and the timestep. We pack all this stuff up % into another parameter vector that we pass into newtonND. paramsNewton = [params U(n,:) t(n+1) dt]; % call newtonND. It will return a column vector that contains the % solution for the n+1 timestep. Transpose it and store it in U. U(n+1, ) = newton ND (guess, tol, fcn, paramsNewton)'; function [root, n] = newton ND (guess, tol, fcn, params) % function [Root, n] = newtonND (guess, tol, fcn, params) % % Find a root of a system of N nonlinear expressions using the % multidimensiuonal Newton method. Works for any N. Guess is % a column vector (length N) with an inital estimate for the root. % tol is convergence % tolerance. params contains constants to be passed to fcn. fcn is handle % to a MATLAB function that computes the nonlinear expressions and the % associated Jacobian. Output root is column vector with N elements. n is % the iteration count. % % fcn has form [F, J] = fcn (X, params). X is column vector with N elements % containing independent variables. params contains constants. F is a % column vector with N elements containing the expressions evaluted with X. % J is the NxN Jacobian matrix. % copy the guess to X. As the algorithm runs, X will contain our % current best estimate to a root. We should really be checking that % guess is a column vector before proceeding X = guess; % call fcn to evaluate the N expressions and the NXN Jacobian matrix. [F, J] = fcn (X, params); n=1; % initialize iteration counter % iterate until the F is within tol of 0. This is a little more % complicated than the 1D newton method because F is a vector that % contains the values of N different functions. The usual way to handle % this is to use the Euclidean length of the vector, which we can get % from the norm() function. For example, for a 2D system with F = [f;g], % norm (F) = sqrt (f^2 + g^2). while norm (F) > tol % the following line is meat of method. Refer to notes. We solve a % linear system to get corrections to X. dx will be a column vector % with N elements dX = J\(-F); % update X by adding the corrections we just calculated X = X+dX; % reevaluate the fucntions and Jacobian [F, J] = fcn (X, params); n=n+1; % increment counter end % we get here when X has converged to a root. Copy it to root and % return root = X; Review the Predator Prey notes. This assignment is to solve the Lotka-Volterra equations using the *backward* Euler method. Follow the procedure I used in class for the FHN equations. You may use the backward EulerND and newtonND examples from class. You will need to write a function called IvBE that will be passed through backward EulerND and into newtonND to evaluate the function value vector and Jacobian matrix needed by newtonND. It will be analogous to fhnBE from class. Also write a script that sets parameter values, timestep increment, etc., then calls backward EulerND and plots the solution. It would be wise to first solve the system using rk4 or eulerND to be sure you are getting a correct solution from backward EulerND. Call your script runLV. Use a time step of 0.001. Set the initial condition for chipmunk population, c, to 1.0 and the initial kitty population, k, to 0.1. At first, use the parameters: alpha = 1 beta = 10 delta=1 gamma=1 This is actually a fixed point of the system of ODEs, so the two populations will stay perfectly balanced at the initial values. Next, make the cats less hungry by reducing beta, then more hungry by increasing beta. Observe what happens to the two populations in the two cases. Then set beta back to 10 and make the cats longer lived by increasing gamma to 10. Again, observe what happens to the populations. Feel free to play with other parameter combinations. Upload runLV.m, LVBE.m and a plot of your solution for the parameters alpha=1, beta=15, delta=1, gamma=1. Your code must be appropriately commented and indented. function [F, J] = fhnBE (Unp1, paramsNewton) % function [F, J] = fhnBE (Unp1, params Newton) % % Used to solve the FHN system of ODEs using the multidimensional backward % Euler method. It is called by newtonND which is called by % backward EulerND. The system is % % % du/dt = c1*u* (u-a)*(1-u) - c2*u*v + Ileak. dv/dt b* (u-d*v) % % Applying the backward Euler method produces two nonlinear expressions % that must be solved in each timestep. % % let unp1 be u(n+1), the value of u in the next timestep we are trying to % find. similarly, vnp1 is v(n+1). un and vn are the known values of u and % v in the current timestep, u(n) and v(n). The two expressions are: % % f(unp1, vnp1) = un + (c1* unp1* (unp1-a)*(1-unp1) - c2unp1*vnp1 + Il )*dt unp1 % g(unp1, vnp1) = vn + b* (unp1 - d*vnp1) *dt % % The input vector Unp1 contains unp1 and vnp1. paramsNewton contains the % constants in the ODE as well as un, vn, and dt. It was packed up by % backward Euler ND and passed into newtonND, which passed it here. The % function returns F, which is f and g stacked into a column vector, and J, % the Jacobian matrix of F % unpack current estimates for unp1 and vnp1. The very first time % newton ND calls this function, these will be un and vn. newton ND will % improve these estimates iteratively until it finds values that when % plugged into f and g make both expressions 0. unp1 = Unp1 (1); vnp1 = Unp1(2); % unpack the constants in the ODE. These were passed into % backward Euler ND as params. a = params Newton (1); b = paramsNewton (2); c1= paramsNewton (3); c2 paramsNewton (4); d = paramsNewton (5); Il = paramsNewton (6); % unpack un and vn un vn params Newton (7); paramsNewton (8); % unpack t(n+1). Time does not appear in the RHSs of the FHN system, so % we don't need it. tnp1 = params Newton (9); %unused % unpack dt dt = paramsNewton (10); % we now have all the info we need to evaluate f and g. f = un + (c1*unp1* (unp1-a)*(1-unp1) - c2*unp1*vnp1 +Il) *dt g = vn + b* (unp1-d*vnp1) *dt - vnp1; F = [f;g]; % stack into column vector end % compute the elements of the Jacobian matrix. dfdunp1 is the % derivative of f with respect to unp1 - dfdunp1 c1*dt* ( -unp1* (unp1-a) + unp1*(1-unp1) + (unp1-a)*(1-unp1) ) - c2*dt*vnp1-1; % the other components are simpler... dfdvnp1 = -c2*dt*unp1; dgdunp1 b*dt; dgdvnp1 = -b*d*dt - 1; = % deriv of f wrt vnp1 % deriv of g wrt unp1 % deriv of g wrt vnp1 J = [dfdunp1 dfdvnp1; dgdunp1 dgdvnp1]; unp1; % assemble Jacobian. derivs of f in top row, of g in second row. Look % at the nonlinear 2D notes to see see why F and J are structured this % way. function [U, t] = backward Euler ND (UO, dt, tend, params, fcn) % function [U, t] = backward Euler ND (U0, dt, tend, params, fcn) % % Solves a *system* of ODEs using the backward Euler method. The calling % sequence is simlar to all our other ODE integrating functions. This uses % the same idea as backward Euler for a *single* ODE, but taking a backward % Euler timestep for a *system* of ODEs results in a *system* of nonlinear % algebraic expressions whose root must be found in each timestep. We use % the multidimensional Newton method to do this. For the FHN example, fcn % will be a handle to fhnBE, which evaluates these expressions % initialize solution array U and time vector t as before. U(1, :) = U0; t = 0:dt: tend; U(length(t), :) = 0; % timestep loop for n-1: length(t)-1 end end % Our initial guess for the solution U at timestep n+1 is just the % solution at timestep n. NewtonND expects its intitial guess for % the root to be in a column vector, so we transpose. guess = U(n, :)'; tol=1.e-8; % convergence tolerance for Newton ND % The params vector passed into this function contains the % constants in the ODEs. For the FHN system, this is a, b, c1, c2, d, % and Ileak. fcn, the function that evaluates the system of % nonlinear expressions we are finding the root to (and its % Jacobian matrix) also needs some other information: the current % U, sometimes t(n+1) and the timestep. We pack all this stuff up % into another parameter vector that we pass into newtonND. paramsNewton = [params U(n,:) t(n+1) dt]; % call newtonND. It will return a column vector that contains the % solution for the n+1 timestep. Transpose it and store it in U. U(n+1, ) = newton ND (guess, tol, fcn, paramsNewton)'; function [root, n] = newton ND (guess, tol, fcn, params) % function [Root, n] = newtonND (guess, tol, fcn, params) % % Find a root of a system of N nonlinear expressions using the % multidimensiuonal Newton method. Works for any N. Guess is % a column vector (length N) with an inital estimate for the root. % tol is convergence % tolerance. params contains constants to be passed to fcn. fcn is handle % to a MATLAB function that computes the nonlinear expressions and the % associated Jacobian. Output root is column vector with N elements. n is % the iteration count. % % fcn has form [F, J] = fcn (X, params). X is column vector with N elements % containing independent variables. params contains constants. F is a % column vector with N elements containing the expressions evaluted with X. % J is the NxN Jacobian matrix. % copy the guess to X. As the algorithm runs, X will contain our % current best estimate to a root. We should really be checking that % guess is a column vector before proceeding X = guess; % call fcn to evaluate the N expressions and the NXN Jacobian matrix. [F, J] = fcn (X, params); n=1; % initialize iteration counter % iterate until the F is within tol of 0. This is a little more % complicated than the 1D newton method because F is a vector that % contains the values of N different functions. The usual way to handle % this is to use the Euclidean length of the vector, which we can get % from the norm() function. For example, for a 2D system with F = [f;g], % norm (F) = sqrt (f^2 + g^2). while norm (F) > tol % the following line is meat of method. Refer to notes. We solve a % linear system to get corrections to X. dx will be a column vector % with N elements dX = J\(-F); % update X by adding the corrections we just calculated X = X+dX; % reevaluate the fucntions and Jacobian [F, J] = fcn (X, params); n=n+1; % increment counter end % we get here when X has converged to a root. Copy it to root and % return root = X;
Expert Answer:
Related Book For
Database Systems Design Implementation and Management
ISBN: 978-1337627900
13th edition
Authors: Carlos Coronel, Steven Morris
Posted Date:
Students also viewed these databases questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
The goal of this assignment is to learn about real-world SDLC failures and apply what we've learned about the SDLC to these "cases". I hope that, by doing this, you will not be involved with (or,...
-
Bruceton Farms Equipment Company had goodwill valued at $80 million on its balance sheet at year-end. A review of the goodwill by the company's CFO indicated that the goodwill was impaired and was...
-
North Korea has a population of 25 million people, of whom 1.1 million are in the military. South Korea has an army of 650,000 out of a population of 49 million. What percentage of the population is...
-
You place an order for 380 units of inventory at a unit price of $130. The supplier offers terms of 1/10, net 30. a. How long do you have to pay before the account is overdue? If you take the full...
-
The 60-kg flowerpot is suspended from wires AB and BC. If the wires have a failure normal stress of fail = 380 MPa, determine the minimum diameter of each wire. Use a factor of safety of 2. A 60 45...
-
Kruger Corporation produces products that it sells for $36 each. Variable costs per unit are $16, and annual fixed costs are $480,000. Kruger desires to earn a profit of $120,000. Required a. Use the...
-
The driver of a car traveling at 31.9 m/s applies the brakes and undergoes a constant deceleration of 1.12 m/s 2 . How many revolutions does each tire make before the car comes to a stop, assuming...
-
The city manager of a large midwestern city was negotiating with the three unions that represented the police, firefighters, and building inspectors over the salaries for these groups of employees....
-
Consider the following very complex projects: The construction of a new elementary school in a busy urban center. List who you think would be your main stakeholders for the project you selected and...
-
Remember arithmetic and symbolic languages used to do symbolic thinking. Are you more of a verbal, visual or symbolic thinker? Explain your answer. Discuss the role symbolic thinking has played in...
-
Identify 2 tools used for backup purposes that would support business continuity to ensure that the data can be accessed during the disaster. Explain who is responsible for the backup. How often...
-
A US government bond has an annual coupon rate of 3% and a face value of $100. The bond pays semi-annual coupons and has 8 years to maturity. The next coupon will be paid 6 months from now. The...
-
State a direction vector for a line parallel to the line y = (x 1). Note: Answer in the form (xo, yo).
-
For a particular Java assembler interface, it is known that the operand stack size has the following probability distribution function: 0 1 2 3 4 . 2 5 . 2 0 . 1 8 . 1 7 . 2 0 What is the Expected...
-
Consider the following. B = {(5, -2), (-2, 1)}, B' = {(-12, 0), (-4, 4)}, %3D -1 [x] (a) Find the transition matrix from B to B'. |-7/12 -1/4 p-1 = 1/2 1/4 (b) Find the transition matrix from B' to...
-
Explain the term "Equivalent Units". Why are they calculated in process costing? [4 Marks] [minimum 350 words]
-
What is a sequence? Write its syntax.
-
What is the difference between a column and a super column in a column family database?
-
Convert the following relational database tables to the equivalent OO conceptual representation. Explain each of your conversions with the help of a diagram. ) The Avion Sales database includes the...
-
Obtain the time variation of the lift and propulsive force coefficients and their plots for the airfoil given by Example 8.5. Assume that the profile pitches about quarter chord point. Example 8.5...
-
Write down a numerical solution algorithm for the LU decomposition solution of the pseudo penta diagonal matrix equation given by (A11.4). A11.4 || B C 2 A2 B2 C2 922 An-1 Bn-1 Cn-1 -1 An Bn R R Rn-1...
-
Obtain Eq. 8.66 as a relation between the wake vorticity and the reduced circulation. Eq. 8.66 w(x) = k(Q; cosx-22, sin x) cos ks +k(Q; sin x+Q, cos x) sinks, Q = Q, +Q;i
Study smarter with the SolutionInn App