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).

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
%

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.

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.

help

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

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.

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