Results 1 to 11 of 11

Math Help - info help for matlab/ODE

  1. #1
    Member
    Joined
    Nov 2005
    Posts
    111

    info help for matlab/ODE

    Hi ,

    I would like to know if someone can help me with a Matlab code about solving a differential equation using Heun's method.
    I have been stuck with it for few days now and I need some help.

    Please let me kow.

    Braddy
    Follow Math Help Forum on Facebook and Google+

  2. #2
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by braddy
    Hi ,

    I would like to know if someone can help me with a Matlab code about solving a differential equation using Heun's method.
    I have been stuck with it for few days now and I need some help.

    Please let me kow.

    Braddy
    Possibly but we will need more information about your
    problem.

    RonL
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Member
    Joined
    Nov 2005
    Posts
    111
    Quote Originally Posted by CaptainBlack
    Possibly but we will need more information about your
    problem.

    RonL
    Thanks . this is the problem:

    Define a general function heunstep(f,tcurr,tnext,xcurr,par) that will take one step of Heun's method to solve a system of first order initial value problems. f is the handle to a function for evaluating the first derivatives.

    tcurr is the current value of the independent variable, tnext is the value of the independent variable at which the solution is sought, xcurr is a column vector containing the current values of the dependent variables, and par is a vector containing any additional parameters required in the evaluation of f. ( for example if x'=rx1+mx2+kx1^3, vector par would be par=[r,m,k])

    heunstep should return a column vector containing the values of the dependent variables at tnext. Design heunstep so that if par is the empty matrix, f will be evaluated at t and x by feval(f,t,x) while if par is not empty, f is evaluated at t and x by feval(f,t,x,par).

    Thank you

    B
    Follow Math Help Forum on Facebook and Google+

  4. #4
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    The following function should do this. But note its untested as
    I am at home at present and so don't have access to a machine
    with Matlab.

    The comments contain a link to a PDF file which provides an
    explanation of the theory behind the method (as if it wasn't
    obvious).

    RonL

    ================================================== =

    function RV=heunstep(f,tcurr,tnext,xcurr,par)
    %
    % function to take one step of Heun's method
    % for integrating an ODE initial value problem
    %
    % Arguments: f-function handle for a function to evaluate the
    % derivatives
    % tcurr-current time
    % tnext-time to step to
    % xcurr-solution at tcurr
    % par-row vector containing additional parameters
    % for the derivative function
    %
    % Return Value: RV col vector xnext, xnext estimated solution at tnext
    % xnext has the same dimensions as xcurr, and this should
    % also be the same as the return value of the function that
    % f is a handle for.
    %
    % reference:
    %http://math.fullerton.edu/mathews/n2003/heunsmethod/Heun'sMethodProof.pdf
    %
    % Adapted from the code for: "Numerical Methods Using MATLAB", by John Mathews from Matlab Central.
    %
    % by CB 2005
    %

    h=tnext-tcurr;

    k1=feval(f,tcurr,xcurr,par);
    k2=feval(f,tnext,xcurr+h*k1,par);
    xnext=xcurr+(h/2)*(k1+k2);

    RV=xnext;
    Last edited by CaptainBlack; June 15th 2007 at 01:33 PM.
    Follow Math Help Forum on Facebook and Google+

  5. #5
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    You will still gave to modify or check that the code given satisfies these requirements:

    heunstep should return a column vector containing the values of the dependent variables at tnext. Design heunstep so that if par is the empty matrix, f will be evaluated at t and x by feval(f,t,x) while if par is not empty, f is evaluated at t and x by feval(f,t,x,par).
    I have now tested the code on my handheld under Lyme - a matlab
    clone, and it appears to work.

    RonL
    Follow Math Help Forum on Facebook and Google+

  6. #6
    hpe
    hpe is offline
    Member hpe's Avatar
    Joined
    Apr 2005
    Posts
    158
    Quote Originally Posted by CaptainBlack
    I have now tested the code on my handheld under Lyme - a matlab clone, and it appears to work.
    Cool
    Follow Math Help Forum on Facebook and Google+

  7. #7
    Member
    Joined
    Nov 2005
    Posts
    111
    Quote Originally Posted by CaptainBlack
    You will still gave to modify or check that the code given satisfies these requirements:



    I have now tested the code on my handheld under Lyme - a matlab
    clone, and it appears to work.

    RonL
    Thank you very much!!
    I will be right back after testing it.
    It seems to be ok.
    B
    Follow Math Help Forum on Facebook and Google+

  8. #8
    Member
    Joined
    Nov 2005
    Posts
    111
    Quote Originally Posted by braddy
    Thank you very much!!
    I will be right back after testing it.
    It seems to be ok.
    B
    Hi it seems working . However, I will be sure when our teacher will give us a sample data.
    Now, I need to generate the real function heun ( with n steps) using heunstep ( you helped me with) as subprogram. I am gonna try to do it.

    Again thank you very much.

    B
    Follow Math Help Forum on Facebook and Google+

  9. #9
    Member
    Joined
    Nov 2005
    Posts
    111

    help

    Quote Originally Posted by braddy
    Hi it seems working . However, I will be sure when our teacher will give us a sample data.
    Now, I need to generate the real function heun ( with n steps) using heunstep ( you helped me with) as subprogram. I am gonna try to do it.

    Again thank you very much.

    B
    okay I tried to create a program using heunstep to create the general function heun for several steps but it does not work.

    I also have problem to understand how to present the solution(T and X)

    I sent The all problem is on the attachment TASK.doc so you can see precisely what it is asked.

    ( if you want I can send you what I tried but as I said it does not work)
    Thank you very much
    B
    Attached Files Attached Files
    Follow Math Help Forum on Facebook and Google+

  10. #10
    hpe
    hpe is offline
    Member hpe's Avatar
    Joined
    Apr 2005
    Posts
    158
    Quote Originally Posted by braddy
    okay I tried to create a program using heunstep to create the general function heun for several steps but it does not work.

    I also have problem to understand how to present the solution(T and X)

    I sent The all problem is on the attachment TASK.doc so you can see precisely what it is asked.

    ( if you want I can send you what I tried but as I said it does not work)
    Thank you very much
    B
    From the instruction sheet for this project:

    This is an individual project. You are encouraged to discuss verbally the project with other students. You can brainstorm together solution approaches, and you can teach each other how to do things with Matlab. However, allowed collaboration ends with this verbal discussion. At no time can you copy work others have done, or have someone else do any of the work for you, or do any of the work for someone else. Everything in the Matlab files themselves must be your work, and your work alone. If you need more help, ask your proctor or instructor for assistance.

    I think we should all respect these instructions.
    Follow Math Help Forum on Facebook and Google+

  11. #11
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    Quote Originally Posted by hpe
    From the instruction sheet for this project:

    This is an individual project. You are encouraged to discuss verbally the project with other students. You can brainstorm together solution approaches, and you can teach each other how to do things with Matlab. However, allowed collaboration ends with this verbal discussion. At no time can you copy work others have done, or have someone else do any of the work for you, or do any of the work for someone else. Everything in the Matlab files themselves must be your work, and your work alone. If you need more help, ask your proctor or instructor for assistance.

    I think we should all respect these instructions.
    A bit tricky for the student, as most of this stuff is in
    text books titled something like: "Numerical Maths with Matlab", it is
    tantamount to an instruction not to visit the library

    RonL
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Getting Less info same stat as more info
    Posted in the Statistics Forum
    Replies: 0
    Last Post: May 15th 2011, 12:12 AM
  2. Is there enough info to do this problem?
    Posted in the Geometry Forum
    Replies: 4
    Last Post: July 30th 2010, 09:35 AM
  3. This problem cant be done without more info
    Posted in the Advanced Statistics Forum
    Replies: 1
    Last Post: October 5th 2009, 02:58 PM
  4. Can this be solved with this info?
    Posted in the Math Topics Forum
    Replies: 6
    Last Post: August 6th 2008, 06:07 AM
  5. Limit...using given info
    Posted in the Calculus Forum
    Replies: 4
    Last Post: December 7th 2007, 06:41 AM

Search Tags


/mathhelpforum @mathhelpforum