Fzero while function files function y f1x y 100exp x

This preview shows page 6 - 10 out of 18 pages.

Fzero while Function Files function y = f1(x) y = 100*exp(-x)-1; end function y = f2(x) y = sin(pi*x); end function y = pro2f(x) y = 100*exp(-x)-1-sin(pi*x); end Command Window Output First root is at 4.179,and then 5.135,5.760,7.387,7.601,9.460,last is at 9.538. Answers to question(s) asked in the homework (if any) Extra credit responses: a) In MATLAB software,every number has numerical precision, if we set (currentRoot – oldRoots) == 0,may be the equation will never correct.so we set (currentRoot – oldRoots) less than a very few number. b) The final zero of the internal iteration algorithm is related to the initial point, but may be far away. Image Output
Week 5 Homework ENGR 112 Fzero while Problem 3 Epidemic Part 5 Comments for grader/additional information (if any) Script File % %% HW4 problem4 % %%SIR model function , there are 5 parameters. % %% parameter 1 means the average connected % %% parameter 2 means number of days infectious. % %% parameter 3 means the Susceptible people % %% parameter 4 means the Infected people % %% parameter 5 means after this steps, the program will finish. % %% part 1 ; SIR_model(10,1.25,500,100,2) ; fprintf( '--------------------------------------------------------\n' ) SIR_model(10,1.25,2000,100,2) ; %% part 2 ; %% SIR_model1 function is similiar to SIR_model function S = 0:500:2000 ; I = 100*ones(1,5) ; R = zeros(1,length(S)) ; SIR_model1(10,1.25,S,I,2) ; %% part 3 ; %% By runing the HW4_part_3 program, we can got the corresponding result %% the number of infected people first increase , then it reach its peak , and decreas to zero. %% part 4 %% there are 5 parameters in DieasesStep function. figure ; for i = 1:length(S) [s1,s2,s3] = DiseaseSimulate(10,1.25,S(i),I(i),R(i),140) ; plot_4_figures(s1,s2,s3) ; end %%part 5 %% figure ; for i = 1:length(S) [s1,s2,s3] = DiseaseSimulate(10,1.25,S(i),I(i),R(i),140) ; IsEpidemic(s1,s2,s3) ; end %% part 6
Week 5 Homework ENGR 112 Fzero while %%figure 1 Slope = zeros(1,2000) ; figure subplot(2,2,1) for i =1:2000 Slope(i) = FindEpidemic(i,20,0) ; x_axis = 1:2000 ; plot(x_axis,Slope) ; xlabel( 'Starting non-sick populations' ) ; ylabel( 'Slope of number of infected' ) ; end %%figure 2 Slope1 = zeros(1,181) ; subplot(2,2,2) for i =20:200 [S,I,R] = DiseaseSimulate(10,1.25,500,i,0,140) ; Slope1(i-19) = min(S+R) ; end X = 20:200 ; plot(X,Slope1) ; xlabel( 'Starting non-sick populations' ) ; ylabel( 'Minimum population for epidemic' ) ; %%figure3 Slope2 = zeros(1,9) subplot(2,2,3) ; for i=2:10 [S,I,R] = DiseaseSimulate(i,1.25,500,100,0,140) ; Slope2(i-1) = min(S+R) ; end X1 = 2:10 ; plot(X1,Slope2) ; xlabel( 'Number of people contacted each day' ) ; ylabel( 'Minimum population for epidemic' ) ; subplot(2,2,4) b1 = linspace(0.5,2,150) ; Slope3 = zeros(1,length(b1)) for i=1:length(b1) [S,I,R] = DiseaseSimulate(10,b1(i),500,100,0,140) ; Slope3(i) = min(S+R) ; end plot(b1,Slope3) ; xlabel( 'Days infectious' ) ; ylabel( 'Minimum population for epidemic' ) ; Function Files %IsEpidemic function IsEpidemic(S,I,R) if (I(1)<I(2)) t2 = plot_4_figures(S,I,R) ; pos = find(max(I)==I) ; subplot(2,2,2) ; plot(t2(pos),I(pos), '+' , 'markersize' ,15) ; fprintf( 'it is a epidemic\n' ) ;
Week 5 Homework ENGR 112 Fzero while else fprintf( 'it is not a epidemic\n' ) ; end end %plot 4 function t2 = plot_4_figures(S_Process,I_Process,R_Process) %%plot the figure length(S_Process) %%figure 1 subplot(2,2,1) t1 = linspace(1,0.05*length(S_Process),length(S_Process)) ; plot(t1,S_Process, 'd' ) ; xlabel( 'time t' ) ; ylabel( 'Susceptible people' ) ; hold on ; subplot(2,2,2) t2 = linspace(1,0.05*length(I_Process),length(I_Process)) ; plot(t2,I_Process, 'd' ) ; xlabel( 'time t ' ) ; ylabel( 'Infected people' ) ; hold on ; subplot(2,2,3) t3 = linspace(1,0.05*length(R_Process),length(R_Process)) ; plot(t3,R_Process, 'd' ) ; xlabel( 'time t' ) ; ylabel( 'Recovered people' ) ; hold on ; subplot(2,2,4) t4 = linspace(1,7,140) ;

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture