×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

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

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

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

(OP)
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


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources