from symbolic expression to function handle?

  • Follow


After many hours of looking for answers in the WWW and of trial and
error (the posting "Convert symbolic expressions into function handle
AND feed them to solver"
<21016409.1153323142094.JavaMail.jakarta@nitrogen.mathforum.org>
 was the closest I found and it got no public answers) I am desperate
enough to ask how one could do symbolic transformations and feed the
resulting system of 1st-order differential equations to a numeric
solver like ode15i. This procedure should be automatic and efficient,
as it would be part of the calculation of a target function, which
should be evaluated within an optimization loop.

As a workaround I made my program write the results of the symbolic
calculations to an m-file for which a function handle can easily be
handed over to the solver-function. Unfortunately this works only by
invoking the program two times in succession because as soon as a
matlab program is started, every change to the m-files within the
working directory seems to be ignored and just created files are not
found. (Adding delays between closing the file for writing and
passing its function handle does not help.)

Another workaround, which I only implemented for explicit
differential equations, was to write a runge-kutta-method myself,
subs(tituting) the values to the symbolic expressions. This actually
works, but is extremely slow and clumsy.

Thank you very much for any help! Maybe there is a list of common
conversions like the one I need, and which I think should be a common
task(?)
0
Reply not13 (52) 4/22/2007 11:12:17 PM

"Reinhard M" <not@home.net> wrote in message 
news:ef54a14.-1@webcrossing.raydaftYaTP...
> After many hours of looking for answers in the WWW and of trial and
> error (the posting "Convert symbolic expressions into function handle
> AND feed them to solver"
> <21016409.1153323142094.JavaMail.jakarta@nitrogen.mathforum.org>
> was the closest I found and it got no public answers) I am desperate
> enough to ask how one could do symbolic transformations and feed the
> resulting system of 1st-order differential equations to a numeric
> solver like ode15i. This procedure should be automatic and efficient,
> as it would be part of the calculation of a target function, which
> should be evaluated within an optimization loop.

Do you need to use the numeric solver or would the symbolic DSOLVE function 
work?

Alternately, create an anonymous function handle like this:

syms t
s = t^2+sin(t);
f = @(time, y) double(subs(s, t, time));
[t, y] = ode45(f, [0 10], 1)

> As a workaround I made my program write the results of the symbolic
> calculations to an m-file for which a function handle can easily be
> handed over to the solver-function. Unfortunately this works only by
> invoking the program two times in succession because as soon as a
> matlab program is started, every change to the m-files within the
> working directory seems to be ignored and just created files are not
> found. (Adding delays between closing the file for writing and
> passing its function handle does not help.)

If the above suggestions don't work and you need to do this, you could be 
running into caching issues.  If you're creating the file under 
$MATLAB/toolbox, try creating it elsewhere and using CLEAR to the file from 
memory.  Read this first, though.

http://www.mathworks.com/support/solutions/data/1-15JM8.html?solution=1-15JM8

-- 
Steve Lord
slord@mathworks.com 


0
Reply slord (13285) 4/23/2007 3:09:08 AM


1 Replies
29 Views

(page loaded in 0.203 seconds)

Similiar Articles:













7/15/2012 11:10:05 AM


Reply: