From: Patricio on
If I use subs (f, t) to evaluate a symbolic funtion, the evaluation time is about 1000 times the "normal" evaluation time of the same function in double precision. Is there any way to transform a symbolic function in a "normal" one before making the evaluation?
From: Alan Weiss on
Patricio wrote:
> If I use subs (f, t) to evaluate a symbolic funtion, the evaluation time
> is about 1000 times the "normal" evaluation time of the same function in
> double precision. Is there any way to transform a symbolic function in a
> "normal" one before making the evaluation?
matlabFunction

For some worked examples in an optimization context, see
http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4nh7.html#brv_i_1
http://www.mathworks.com/products/optimization/demos.html?file=/products/demos/shipping/optim/symbolic_optim_demo.html

Alan Weiss
MATLAB mathematical toolbox documentation
From: Patricio on
Dear Alan: Apparently I did not explain clearly my problem. I will illustrate it with the example below:

% Evaluation time comparision
clc
clear all
syms x x1 x2
f=(1.4-3*x)*sin(18*x);
t=0.6;
%
% f(t) evaluation time
%
tic
ft=subs (f,t)
tftsym=toc % Time using the subs function (the result is 5607 for one of my iteration)
tic
ft=(1.4-3*t)*sin(18*t)
tftdouble=toc % time using the "normal" double presicion function
factor=tftsym/tftdouble % Quotient of the subs function time divided by "normal" double presicion function
%
% f '(t) first derivative evaluation time
%
f2=diff(f)
tic
f2t=subs(f2,t)
tf2tsym=toc
% ¿How to evaluate f2t on "normal" double presicion?

As you see I need to be able to get the explicit function for the derivative of the symbolic function in order to improve the total calculation time. This should be done without stopping the program to see and copy the explicit function f2.
On the manuals you send me I could not get this answer.

thank you for your help.

Alan Weiss <aweiss(a)mathworks.com> wrote in message <hpa2t4$8l7$3(a)fred.mathworks.com>...
> Patricio wrote:
> > If I use subs (f, t) to evaluate a symbolic funtion, the evaluation time
> > is about 1000 times the "normal" evaluation time of the same function in
> > double precision. Is there any way to transform a symbolic function in a
> > "normal" one before making the evaluation?
> matlabFunction
>
> For some worked examples in an optimization context, see
> http://www.mathworks.com/access/helpdesk/help/toolbox/optim/ug/brn4nh7.html#brv_i_1
> http://www.mathworks.com/products/optimization/demos.html?file=/products/demos/shipping/optim/symbolic_optim_demo.html
>
> Alan Weiss
> MATLAB mathematical toolbox documentation
From: Walter Roberson on
On 10-04-04 3:49 PM, Patricio wrote:

> As you see I need to be able to get the explicit function for the
> derivative of the symbolic function in order to improve the total
> calculation time.

And he answered your question: use matlabFunction . It takes a symbolic
formula and creates a Matlab function that evaluates floating point
values for that formula.
From: Patricio on
Walter Roberson <roberson(a)hushmail.com> wrote in message <hpbhfg$605$1(a)canopus.cc.umanitoba.ca>...
> On 10-04-04 3:49 PM, Patricio wrote:
>
> > As you see I need to be able to get the explicit function for the
> > derivative of the symbolic function in order to improve the total
> > calculation time.
>
> And he answered your question: use matlabFunction . It takes a symbolic
> formula and creates a Matlab function that evaluates floating point
> values for that formula.

Dear Walter: I used the follow¡ng exemple:

% Symbolic Math Toolbox&#8482; 5 User&#8217;s Guide (Exemple page 3-130)
clc
clear all
syms x y
r = sqrt(x^2 + y^2);
ht = matlabFunction(tanh(r))

and I got the error:

"??? Undefined function or method 'matlabFunction' for input arguments of type 'sym'.
Error in ==> Symbolic_Math_Toolbox_Exemple at 6
ht = matlabFunction(tanh(r))"

Coul you help me please?