Results 1 to 2 of 2

Thread: Matlab Plotting Euler Iteration Against Exact Solution how to Set Initial Condition

  1. #1
    Member
    Joined
    Mar 2016
    From
    Australia
    Posts
    170

    Matlab Plotting Euler Iteration Against Exact Solution how to Set Initial Condition

    Hi

    I have the following code to plot an approximation using Euler's iteration against the exact value of the function.

    I have used x and y for time and population when coding the Euler iterations and t and m for time and population when plotting the exact function. I can't work out how to initialise the m value when plotting the exact function. M(0)=13. When executed the plot looks correct except for that.

    "%Compute and Graph Euler's Iteration of dM/dt=-1/40M(M-30) (using x and y)
    %Graph Exact Solution of m=30./(1+((17/3)*exp(-3.*t/4)))
    clear;
    format short;
    x=0; %Initialise x value
    y=13; %Initialise y value
    dx=1; %Step size
    n=20; %Number of values to be calculated
    for i=1:n
    y(i+1)=y(i)+dx.*(-1/40*y(i).*(y(i)-30));
    x(i+1)=x(i)+dx;
    end
    disp(' x y')
    disp([x' y'])
    t=0:1:20; %Set range of t being alternate units for time in years
    m=30./(1+((17/3)*exp(-3.*t/4))); %Population from Exact Function
    plot(x,y,t,m)
    xlabel('Time in Years');
    ylabel('Population')
    title('Graph Showing Euler Approximation and Exact Value of Function')"

    Wondering if anyone is able to help.

    Kind regards
    Beetle
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Super Member Rebesques's Avatar
    Joined
    Jul 2005
    From
    My house.
    Posts
    655
    Thanks
    41

    Re: Matlab Plotting Euler Iteration Against Exact Solution how to Set Initial Conditi

    Recode with m(1)=13, as matlab cannot accept zero as an index.
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Euler's Iteration Scheme
    Posted in the Calculus Forum
    Replies: 5
    Last Post: Apr 20th 2016, 07:07 AM
  2. Euler's Method. Finding exact solution
    Posted in the Calculus Forum
    Replies: 5
    Last Post: Oct 13th 2015, 08:45 PM
  3. Replies: 1
    Last Post: Aug 26th 2014, 09:03 PM
  4. Find a Particular Solution, given initial condition
    Posted in the Differential Equations Forum
    Replies: 3
    Last Post: Sep 30th 2010, 10:33 AM
  5. Find the solution that solves the initial condition.
    Posted in the Differential Equations Forum
    Replies: 2
    Last Post: Sep 12th 2008, 08:22 PM

Search Tags


/mathhelpforum @mathhelpforum