Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Symbolic vector function?

Subject: Symbolic vector function?

From: Joerg Buchholz

Date: 25 May, 2012 17:35:16

Message: 1 of 6

Declare a symbolic function:

>> syms r(la)

Define the function:

>> r(la) = la*[3 2 1]
 
r(la) =
 
[ 3*la, 2*la, la]

How do you access the first element of the function?

It seems to be quite an unwise idea to use the same round parantheses for vector index and symbolic function variable syntax ...

Jörg

Subject: Symbolic vector function?

From: Steven_Lord

Date: 25 May, 2012 20:45:17

Message: 2 of 6



"Joerg Buchholz" <buchholz@hs-bremen.de> wrote in message
news:jpofsk$doc$1@newscl01ah.mathworks.com...
> Declare a symbolic function:
>
>>> syms r(la)

Don't do this. Instead do either:

syms r

or:

r = sym('r(la)');

Use the latter syntax if you're doing something like:

r = sym('r(la)');
dr = diff(r, la);
subs(dr, r, sin(la))

> Define the function:
>
>>> r(la) = la*[3 2 1]

syms la
r = la*[3 2 1];
r(1)

> r(la) =
>
> [ 3*la, 2*la, la]
>
> How do you access the first element of the function?
>
> It seems to be quite an unwise idea to use the same round parantheses for
> vector index and symbolic function variable syntax ...

Agreed.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Symbolic vector function?

From: Star Strider

Date: 25 May, 2012 21:49:30

Message: 3 of 6

"Joerg Buchholz" <buchholz@hs-bremen.de> wrote in message <jpofsk$doc$1@newscl01ah.mathworks.com>...
> Declare a symbolic function:
>
> >> syms r(la)
>
> Define the function:
>
> >> r(la) = la*[3 2 1]
>
> r(la) =
>
> [ 3*la, 2*la, la]
>
> How do you access the first element of the function?
>
> It seems to be quite an unwise idea to use the same round parantheses for vector index and symbolic function variable syntax ...
>
> Jörg

-----------------------------------------------------------

I don't even understand how you did that. I wasn't aware it was even possible, and I got nothing but errors when I tried it (2011b) in MATLAB (not MuPAD). I can't find anything in the Symbolic Math Toobox Documentation that mentions creating functions like that.

Subject: Symbolic vector function?

From: Joerg Buchholz

Date: 26 May, 2012 12:14:07

Message: 4 of 6

Star, your post is so 2011! ;-)

As of R 2012a you can finally declare symbolic functions:

>> syms f(x)

define the function:

>> f(x) = 1 + cos (x)
 
f(x) =
 
cos(x) + 1

and compute function values without the subs command (something my students have intuitively tried again and again):

>> f(0)
 
ans =
 
2

This is great!

But in a MATrix LABoratory we might hope that this does not only work in the scalar case. And indeed, we can define a straight line in symbolic parameterized vector form:

>> syms r(la)
>> r(la) = [1 2 3] + la*[4 5 6]
 
r(la) =
 
[ 4*la + 1, 5*la + 2, 6*la + 3]

We can now compute r for la=1 (without subs):

>> r(1)
 
ans =
 
[ 5, 7, 9]

Great!

Now we want to ezplot3 the line. We need the single components of the vecotr r. We could do it by hand:

>> ezplot3 (4*la + 1, 5*la + 2, 6*la + 3)

But there should be a way to use the symbolic vector r directly. Something like:

>> ezplot3 (r(la)(1), r(la)(2), r(la)(3))

Unfortunately we get:

Error: ()-indexing must appear last in an index expression.

Steven, is there a way to plot the line if it is defined as a symbolic vector function?

Jörg

Subject: Symbolic vector function?

From: Star Strider

Date: 26 May, 2012 14:31:38

Message: 5 of 6

"Joerg Buchholz" <buchholz@hs-bremen.de> wrote in message <jpqhef$2ms$1@newscl01ah.mathworks.com>...
> Star, your post is so 2011! ;-)
>
> As of R 2012a you can finally declare symbolic functions:
>
> Jörg

---------------------------------------------------------------------

Cool! I already bought 2012a, but usually wait a couple months to download and install it to allow time for TMW to discover and fix any bugs in the initial release.

Subject: Symbolic vector function?

From: Christopher Creutzig

Date: 14 Jun, 2012 15:16:03

Message: 6 of 6

On 25.05.12 19:35, Joerg Buchholz wrote:
> Declare a symbolic function:
>
>>> syms r(la)
>
> Define the function:
>
>>> r(la) = la*[3 2 1]
>
> r(la) =
>
> [ 3*la, 2*la, la]
>
> How do you access the first element of the function?

Conceptually, a function does not have elements. You could get the first
element of the function body/definition/formula, using something like this:

rf=formula(r);
rf(1)

> It seems to be quite an unwise idea to use the same round parantheses for vector index and symbolic function variable syntax ...

Well, that double usage for indexing and function calls is one of the
things MATLAB inherited from Fortran, I think.


Christopher

Tags for this Thread

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.

Contact us