Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the demographics equation derived in class to make a function which finds the population histories for each of 4 population groups. Migration into group

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Use the demographics equation derived in class to make a function which finds the population histories for each of 4 population groups. Migration into group 2 will be defined by a pulse function. SETUP: parameters= [ b2,d1,d2,d3,d4,112,123,t34] where b2, birth rate in group 2 di, death rates in group Pi tij, transition from group Pi to group Pj due to ageing M2effect, rectangular pulse defined by [Mann2,tStartM2,tEndM2] initconds= [ Pinit1, Pinit2, Pinit3,Pinit4] timedata= [tinit,tfinal,delt] RESULTS: P1, P2, P3,P4, group time histories M2, M2 time history Function C Rese 1 function (P1, P2, P3, P4,M2]= Demographics_2_fcn(parameters,M2effect, initconds, timedata) 2 3 4 5 6 7 end 8 Code to call your function C Reset 1 fprintf(" RUN Demographics_2 '); 2 3 % Parameters 4 b2= .02; 5 dl= .004; d2= .0075; d3= .012; d4= .019; 6 t12= .067; t23= .04; t34= .04; 7 8 % Migration effect M2 9 M2 ann= 80; 10 tStartM2= 20; 11 tEndM2= 50; 12 13 % Initial conditions (in 1000's for convenience) 14 Pinit1= 1200; 15 Pinit2= 1000; 16 Pinit3= 800; 17 Pinit4= 600; 18 19 % Solution control data 20 tinit= 0.; 21 tfinal= 100.; 22 delt= 0.5; 24 % SIMULATION SECTION 25 parameters= [b2, di, d2, d3, 04, t12, t23, t34); % bundle for convenience 26 M2effect= [M2ann, tStartM2, tEndM2]; 27 initconds= [Piniti, Pinit2, Pinit3, Pinit4]; 28 timedata= [tinit, tfinal, delt]; 29 30 [P1, P2, P3, P4,M2)= Demographics_2_fcna 31 parameters,M2effect, initconds, timedata); 32 33 % DISPLAY RESULTS SECTION 34 fprintf(' Demographics setup for Case 2: '); 35 fprintf(" b2=%5.4f ', b2); 36 fprintf( d1=%5.4f, d2=%5.4f, d3=%5.4f, d4=%5.4f ',di, d2,d3,04); 37 fprintf( t12=%6.4f, t23=%6.4f, t34=%6.4f ', t12,t23, t34); 38 fprintf(' Mann=%6.0f, tStartM2=84.0f, tEndM2=%4.0f ',... 39 M2ann, tStartM2, tEndM2); 40 fprintf(' initconds: %6.0f,%6.0f,%6.0f,%6.0f ', initconds (1,:)); 41 fprintf(' tinit=%3.1f., tfinal=%6.1f, delt=%6.2f ', tinit,tfinal, delt); 42 43% display starting and ending values in tabular format 44 fprintf(' Demographics results for Case 2: '); 45 nsteps= round((tfinal-tinit)/delt); 46 47 t= tinit: delt:tfinal; 48 fprintf(" Results at start and at finish '); 49 fprintf(" time P1 P2 P3 P4 '); 50 fmt1= '%7.2f %7.0f %7.0f %7.0f %7.0f %8.0f '; 51 for i=1:5 52 fprintf(fmt1, t(i),P1(i),P2(i),P3(i),P4(i)); 53 end 54 fprintf(' '); 55 for i=nsteps-4:nsteps+1 56 fprintf(fmt1, t(i),P1(i), P2(i),P3(i),P4(i)); 57 end 58 59 figure 60 subplot(3,1,1) 61 plot(t,P1(:),'-',t,P2(:),'--', 'LineWidth',2) 62 title( 'Demographics 1: P1, P2 histories, in 1000''s') 63 xlabel('t, years') 64 ylabel('P1, P2') 65 legend ( 'P1','P2') 66 grid on 67 68 subplot(3,1,2) 69 plot(t,P1(:),'-',t,P2(:),'--',t,P3(:),'-,',t,P4(:),':', 'LineWidth',2) 70 title('P1, P2, P3, P4 histories, in 1000''s') 71 %xlabel('t, years') 72 ylabel('P1, P2, P3, P4') 73 legend ( 'P1','P2', 'P3', 'P4') 74 grid on 75 76 subplot(3,1,3) 77 plot(t,M2,'-', 'LineWidth',2) 78 title('Migration effect M2, in 1000''s') 79 %xlabel('t, years') 80 ylabel('M2') 81 grid on 82 83 fprintf(' ') 84 % Assessment: M2 is correct P1 is Correct P2 is Correct P3 is correct P4 is correct Use the demographics equation derived in class to make a function which finds the population histories for each of 4 population groups. Migration into group 2 will be defined by a pulse function. SETUP: parameters= [ b2,d1,d2,d3,d4,112,123,t34] where b2, birth rate in group 2 di, death rates in group Pi tij, transition from group Pi to group Pj due to ageing M2effect, rectangular pulse defined by [Mann2,tStartM2,tEndM2] initconds= [ Pinit1, Pinit2, Pinit3,Pinit4] timedata= [tinit,tfinal,delt] RESULTS: P1, P2, P3,P4, group time histories M2, M2 time history Function C Rese 1 function (P1, P2, P3, P4,M2]= Demographics_2_fcn(parameters,M2effect, initconds, timedata) 2 3 4 5 6 7 end 8 Code to call your function C Reset 1 fprintf(" RUN Demographics_2 '); 2 3 % Parameters 4 b2= .02; 5 dl= .004; d2= .0075; d3= .012; d4= .019; 6 t12= .067; t23= .04; t34= .04; 7 8 % Migration effect M2 9 M2 ann= 80; 10 tStartM2= 20; 11 tEndM2= 50; 12 13 % Initial conditions (in 1000's for convenience) 14 Pinit1= 1200; 15 Pinit2= 1000; 16 Pinit3= 800; 17 Pinit4= 600; 18 19 % Solution control data 20 tinit= 0.; 21 tfinal= 100.; 22 delt= 0.5; 24 % SIMULATION SECTION 25 parameters= [b2, di, d2, d3, 04, t12, t23, t34); % bundle for convenience 26 M2effect= [M2ann, tStartM2, tEndM2]; 27 initconds= [Piniti, Pinit2, Pinit3, Pinit4]; 28 timedata= [tinit, tfinal, delt]; 29 30 [P1, P2, P3, P4,M2)= Demographics_2_fcna 31 parameters,M2effect, initconds, timedata); 32 33 % DISPLAY RESULTS SECTION 34 fprintf(' Demographics setup for Case 2: '); 35 fprintf(" b2=%5.4f ', b2); 36 fprintf( d1=%5.4f, d2=%5.4f, d3=%5.4f, d4=%5.4f ',di, d2,d3,04); 37 fprintf( t12=%6.4f, t23=%6.4f, t34=%6.4f ', t12,t23, t34); 38 fprintf(' Mann=%6.0f, tStartM2=84.0f, tEndM2=%4.0f ',... 39 M2ann, tStartM2, tEndM2); 40 fprintf(' initconds: %6.0f,%6.0f,%6.0f,%6.0f ', initconds (1,:)); 41 fprintf(' tinit=%3.1f., tfinal=%6.1f, delt=%6.2f ', tinit,tfinal, delt); 42 43% display starting and ending values in tabular format 44 fprintf(' Demographics results for Case 2: '); 45 nsteps= round((tfinal-tinit)/delt); 46 47 t= tinit: delt:tfinal; 48 fprintf(" Results at start and at finish '); 49 fprintf(" time P1 P2 P3 P4 '); 50 fmt1= '%7.2f %7.0f %7.0f %7.0f %7.0f %8.0f '; 51 for i=1:5 52 fprintf(fmt1, t(i),P1(i),P2(i),P3(i),P4(i)); 53 end 54 fprintf(' '); 55 for i=nsteps-4:nsteps+1 56 fprintf(fmt1, t(i),P1(i), P2(i),P3(i),P4(i)); 57 end 58 59 figure 60 subplot(3,1,1) 61 plot(t,P1(:),'-',t,P2(:),'--', 'LineWidth',2) 62 title( 'Demographics 1: P1, P2 histories, in 1000''s') 63 xlabel('t, years') 64 ylabel('P1, P2') 65 legend ( 'P1','P2') 66 grid on 67 68 subplot(3,1,2) 69 plot(t,P1(:),'-',t,P2(:),'--',t,P3(:),'-,',t,P4(:),':', 'LineWidth',2) 70 title('P1, P2, P3, P4 histories, in 1000''s') 71 %xlabel('t, years') 72 ylabel('P1, P2, P3, P4') 73 legend ( 'P1','P2', 'P3', 'P4') 74 grid on 75 76 subplot(3,1,3) 77 plot(t,M2,'-', 'LineWidth',2) 78 title('Migration effect M2, in 1000''s') 79 %xlabel('t, years') 80 ylabel('M2') 81 grid on 82 83 fprintf(' ') 84 % Assessment: M2 is correct P1 is Correct P2 is Correct P3 is correct P4 is correct

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Neo4j

Authors: Gregory Jordan

1st Edition

1484200225, 9781484200223

More Books

Students also viewed these Databases questions