Question

Using MatLab, complete the following:

A model for extermination of a roach population in an area p(t) is based on the assumption that their growth rate decreases o

0 0
Add a comment Improve this question Transcribed image text
Answer #1


Matlab code for Midpoint method clear all close all %function for solving ODE using midpoint method fun- (t,p1/60)-((3*t)./50For step size h-0.01 and p(0)-9 At t-20.000000 value of p-0.887411 For step size h-0.01 and p(o)-20 At t-20.0000 value of p-0

%%Matlab code for Midpoint method
clear all
close all
%function for solving ODE using midpoint method
fun=@(t,p) ((1/60)-((3*t)./50)).*p-1;
    t(1)=0;p(1)=9;    %initial conditions
    t_in=t(1);        %Initial t
    t_max=20;         %Final t
    %Midpoint iterations
    h=0.01;
    n=(t_max-t_in)/h;
    for i=1:n
     
        k1=h*fun(t(i),p(i));
        k2=h*fun(t(i)+(1/2)*h,p(i)+(1/2)*k1);
      
        t(i+1)=t_in+i*h;
        p(i+1)=double(p(i)+k2);
       
    end
    hold on
    plot(t,p,'linewidth',2)
    fprintf('For step size h=%2.2f and p(0)=9\n ',h)
    fprintf('\n\tAt t=%f value of p=%f.\n\n',t(end),p(end))
    clear t; clear p;
  
    t(1)=0;p(1)=50;    %initial conditions
    t_in=t(1);        %Initial t
    t_max=20;         %Final t
    %Midpoint iterations
    h=0.01;
    n=(t_max-t_in)/h;
    for i=1:n
     
        k1=h*fun(t(i),p(i));
        k2=h*fun(t(i)+(1/2)*h,p(i)+(1/2)*k1);
      
        t(i+1)=t_in+i*h;
        p(i+1)=double(p(i)+k2);
       
    end

    fprintf('For step size h=%2.2f and p(0)=20\n ',h)
    fprintf('\n\tAt t=%f value of p=%f.\n\n',t(end),p(end))
    plot(t,p,'linewidth',2)
    box on
    xlabel('time t')
    ylabel('p(t)')
    title('p(t) vs. t plot using midpoint method')
    legend('p(0)=9','p(0)=50')
  
   %%%%%%%%%%%%%%%%%% End of Code %%%%%%%%%%%%%%%%%%
  
   

Add a comment
Know the answer?
Add Answer to:
Using MatLab, complete the following: A model for extermination of a roach population in an area p(t) is based on the assumption that their growth rate decreases over time at a rate of 3/50 per day,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT