Thread Subject: convert symbolic function

Subject: convert symbolic function

From: ture vp

Date: 8 May, 2008 20:27:02

Message: 1 of 4

Maybe an obvious question for some of you:

Say I define the function f as:

syms a b x
f=a*x+b

Later on in my code I would like to evaluate this function
for given values of a,b and x. How can I do this?

Ture

Subject: convert symbolic function

From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)

Date: 8 May, 2008 21:11:53

Message: 2 of 4

In article <fvvnmm$ad9$1@fred.mathworks.com>, Ture VP <turevp@gmail.com> wrote:
>Maybe an obvious question for some of you:

>Say I define the function f as:

>syms a b x
>f=a*x+b

>Later on in my code I would like to evaluate this function
>for given values of a,b and x. How can I do this?

I haven't used the symbolic toolbox, but by scanning past postings,
it appears to me that there are two strategies:

1) use subs() to substitute the specific values in for the symbols; or

2) assign values to the variable names (which might remove the name's
status as being a symbol), and then use vpa() to evaluate the expression.

vpa() is the Variable Precision Arithmetic command and it tries to
resolve things as far as possible to numeric values with the
number of digits you have set up via digits(). This can result in
long numbers where you only want simple numbers -- e.g., if you
wanted to preserve sqrt(2) as a factor in the expression, then
you would not use vpa() because it would evaluate to 1.414<whatever>;
similarily, 2/3 would become 0.6666<etc> . vpa() is suitable for
-numeric- evaluation of a function, but not for -symbolic- evaluation.
For example if your expression had tan(x) - 2*sin(x)/cos(x)
and you wanted that resolved symbolically to -tan(x) then you would not
use vpa, which would go ahead and calculate tan(x) and sin(x) and cos(x)
numerically and do the division and so on.
--
   "Any sufficiently advanced bug is indistinguishable from a feature."
   -- Rich Kulawiec

Subject: convert symbolic function

From: Steven Lord

Date: 8 May, 2008 21:15:00

Message: 3 of 4


"Ture VP" <turevp@gmail.com> wrote in message
news:fvvnmm$ad9$1@fred.mathworks.com...
> Maybe an obvious question for some of you:
>
> Say I define the function f as:
>
> syms a b x
> f=a*x+b
>
> Later on in my code I would like to evaluate this function
> for given values of a,b and x. How can I do this?

Use the SUBS function.

--
Steve Lord
slord@mathworks.com


Subject: convert symbolic function

From: ture vp

Date: 8 May, 2008 21:30:18

Message: 4 of 4

"Steven Lord" <slord@mathworks.com> wrote in message
<fvvqgk$qje$1@fred.mathworks.com>...
>
> "Ture VP" <turevp@gmail.com> wrote in message
> news:fvvnmm$ad9$1@fred.mathworks.com...
> > Maybe an obvious question for some of you:
> >
> > Say I define the function f as:
> >
> > syms a b x
> > f=a*x+b
> >
> > Later on in my code I would like to evaluate this function
> > for given values of a,b and x. How can I do this?
>
> Use the SUBS function.
>
> --
> Steve Lord
> slord@mathworks.com
>
>

Exactly what I was looking for.
Not sure why I missed that one when going through the
Function Reference Alphabetical List for the symbolic math
toolbox.

Thanks!

Ture

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
symbolic toolbox Ture VP 8 May, 2008 16:30:37
syms Ture VP 8 May, 2008 16:30:37
rssFeed for this Thread

Public Submission Policy

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Disclaimer prior to use.

Contact us at files@mathworks.com