Path: news.mathworks.com!not-for-mail
From: "Steven Lord" <slord@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: objects containing functions
Date: Mon, 29 Mar 2010 13:53:13 -0400
Organization: The MathWorks, Inc.
Lines: 29
Message-ID: <hoqpdm$nq9$1@fred.mathworks.com>
References: <hoqo8l$4vl$1@fred.mathworks.com>
Reply-To: "Steven Lord" <slord@mathworks.com>
NNTP-Posting-Host: lords.dhcp.mathworks.com
X-Trace: fred.mathworks.com 1269885174 24393 172.31.44.65 (29 Mar 2010 17:52:54 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 29 Mar 2010 17:52:54 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.5512
X-RFC2646: Format=Flowed; Response
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5579
Xref: news.mathworks.com comp.soft-sys.matlab:621598


"Simon Preston" <preston.simon+mathsworks@gmail.com> wrote in message 
news:hoqo8l$4vl$1@fred.mathworks.com...
> Hi all,
>
> I would like to represent a dynamical model (defined in terms of ODEs, 
> i.e., dx_dt = f(x,t;theta)) as a Matlab object.  To do so, I would like 
> the object to contain the function f as a property.
>
> One way to achieve this is to define f as an inline function.  The trouble 
> doing this is that solving the model with an ODE solver requires repeated 
> evaluations of this inline function, which is extemely slow.
>
> I could of course have f as a function separate from my model object, but 
> this loses the nice convenient and tidy property that the model object is 
> self contained.
>
> Any suggestions how I could do this better - i.e. ways of defining f 
> within the object, but so it is as fast to evaluate as if it were a 
> separate function?

Use a function handle.

-- 
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ