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
Thanks . this is the problem:Originally Posted by CaptainBlack
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
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;
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 matlabheunstep 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).
clone, and it appears to work.
RonL
Hi it seems working . However, I will be sure when our teacher will give us a sample data.Originally Posted by braddy
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.Originally Posted by braddy
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:Originally Posted by braddy
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.