1. ## Ode45

Hello there.

Okay, let's say I have a system of 1st order ODEs to solve. So I create a function file which describes these functions called, say:

Code:
 function dy = myfunction(t,y)
.

Now, to solve these ODEs using ODE45, I'd simply write a script file which says:

Code:
[t,y] = ode45(@myfunction, [t0 tf], [y10 y20 y30 y40...yn0])
, and ODE45 will perform the integration and spit out the solution in the vector y.

Now let's say I want to do the same thing again, but rather than use ODE45, I'd like to use my own integration scheme. So I begin to write my function file to perform the integration using, say, a modified Euler method. How would I write the file in such a way that it takes the same inputs as ode45, and produces the same outputs? How to I write my integration scheme to use myfunction(t,y)? I'm rather confused about it, and scanning over the ODE45 code to see how ODE45 does it is a bit beyond my scope.

2. I think you need to look into "function_handles and "anonymous functions" if I understand your question correctly?

Example:
Code:
EDU>> f = @(x)magic(x)

f =

@(x)magic(x)

EDU>> f(2)

ans =

1     3
4     2

EDU>> f(5)

ans =

17    24     1     8    15
23     5     7    14    16
4     6    13    20    22
10    12    19    21     3
11    18    25     2     9

EDU>>
Regards Elbarto

3. Blah!

4. When you pass your function into ode45, you are passing it in as a function_handle. This allowes ode45 to assign its own name to some instance of your function, which in my example I called f. If you already know how to do the integration and want to create a function like ode45, you will need to use function_handles.

This might help:
Function Handles (Programming and Data Types)

You are essentially createing a function_handle when you write
Code:
@mydifferentialequation
Maybe I am still misreading the question? This is the method I used when I wrote my own implementation of newtons method, I let the user pass a function_handle for f(x) and a second function_handle for df/dx.

Elbarto

5. Originally Posted by elbarto
When you pass your function into ode45, you are passing it in as a function_handle. This allowes ode45 to assign its own name to some instance of your function, which in my example I called f. If you already know how to do the integration and want to create a function like ode45, you will need to use function_handles.

This might help:
Function Handles (Programming and Data Types)

You are essentially createing a function_handle when you write
Code:
@mydifferentialequation
Maybe I am still misreading the question? This is the method I used when I wrote my own implementation of newtons method, I let the user pass a function_handle for f(x) and a second function_handle for df/dx.

Elbarto
Would it be too much to request an excerpt of example code?

6. Got it!