Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations waross on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help: how to speed up function evaluation (feval)?

Status
Not open for further replies.

xiaopc

Structural
Oct 25, 2005
1
Hi all,


I have a set of functions that I need to numerically integrate in each
New-raphson iteration step. Here is what I did:


1) There are about 50 functions (9 parameters in each, 7 plug-in
parameters and two integrating parameters) that involve derivatives and
second derivatives, therefore to make sure I get correct expressions. I
use symbolic tool box to get those functions and change them to
strings. They are really long and complicated;


2) In each iteration, for each function, I plug in updated values for
plug-in parameters by using "regexprep" in those "function" strings and
then make inine functions from those strings with respect to
integrating parameters by using "inline" function.


3) In the last step, I plug in the function expression I get in 2) to
the integrating function, which takes a function (handle or inline
object) as an input argument. Since it is numerical integration, it
needs function evaluation at hundreds of points. (feval is used).


The program works fine but it runs very slow. I used Profiler and found
that a big chunk of time is used in function evaluation (feval).
Through further investigation, I found that the slowness is due to the
fact that when "regexprep" replaces parameters with new values, it
doesn't simply the function expression, e.g., 1/2*6^1 is not simplified
as 3, therefore function expression is unnecessarily complicated and
causes slow function evaluation. (I tried a simpler function expression
in feval and it ran much faster). I did try using symbolic functions
(subs, simplify...) to make substitution and simplication before
changing to inline function objects but it took even longer
time(numerous calls to maple functions).


I guess the last solution is that I manually simply those functions up
front as much as possible but once again there are so many of them and
they are messy.


I wonder if anyone knows of any fast way to plug-in those parameters
and simply expression after the plug-in, in an efficient manner. I
would very much appreciate if you can provide any lead on this. Thanks
for reading such long message and have a good day!


xp


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor