|
|
from symbolic expression to function handle?
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: Converting symbolic piecewise functions using matlabFunction ...matlabFunction - Convert symbolic expression to function handle or ... This MATLAB function converts the symbolic expression or function f to a ... Assigning value to symbolic expressions in vector - comp.soft-sys ...Hello, I have a vector witch contains several symbolic expressions, and another ... the expression BEFORE calling DSOLVE. fcn = subs ... how to solve symbolic function ... fittype with function handle / anonymous function - comp.soft-sys ...How can I use a function handle / anonymous function for fittype: f = @(x,a ... x,a)') I don't believe FITTYPE supports specifying a function handle as the expression ... conversion from symbolic to double - comp.soft-sys.matlab ...> If the input expression contains a symbolic variable, use the VPA function > instead. ... Assigning value to symbolic expressions in vector - comp.soft ... Error using ==> mupadmex - comp.soft-sys.matlab... in MuPAD command: DOUBLE cannot convert the input expression into a > double > array. > > If the input expression contains a symbolic variable, use the VPA function ... Using syms in Matlab R2010a - comp.soft-sys.matlab>> > >> > If the input expression contains a symbolic variable, use the VPA function >> > instead. ... the double integration is > going to be a symbolic expression ... integrating the symbolic normcdf - comp.soft-sys.matlabNORMCDF is a function from Statistics Toolbox that's defined for _numeric_ inputs, not symbolic. Using the expression from the documentation for NORMCDF, you can ... Defining function in Mupad - comp.soft-sys.matlabI need a symbolic function in mupad like test(k)= 1 for k0 Where ... Math - Utah :: School of Computing Defining Symbolic Expressions . We can define symbolic functions ... symbolic variables - comp.soft-sys.matlabSymbolic Math (subs function) - comp.soft-sys.matlab PROGRAM: F=[1 5 2 6 4 1] A=[1 1 1 0 0 ... Note To substitute a matrix A into the symbolic expression f, use the command ... how to solve symbolic function with initial values - comp.soft-sys ...> > but the function is symbolic, it's not double. how to ... me A topic for comp.math ... the expression BEFORE calling DSOLVE. fcn = subs ... how to solve symbolic function ... Convert symbolic expression to function handle or file - MATLABThis MATLAB function converts the symbolic expression or function f to a MATLAB function with the handle g. Generating Code from Symbolic Expressions :: Using Symbolic Math ...matlabFunction generates input variables in alphabetical order from a symbolic expression. That is why the function handle in Generating a Function Handle has x before y: 7/15/2012 11:10:05 AM
|
|
|
|
|
|
|
|
|