Thread Subject: How do I determine whether a variable is numerical or symbolic?

Subject: How do I determine whether a variable is numerical or symbolic?

From: Gerry Puckett

Date: 27 Oct, 2008 20:18:01

Message: 1 of 3

I'm using the symbolic toolbox to determine certain values; e.g.,

Column_1 = int(3 / 2 + tanh(z), z, -3/2, -1/2)
Column_2 = int(3 / 2 + tanh(z), z, -1/2, 1/2)
Column_3 = int(3 / 2 + tanh(z), z, 1/2, 3/2)

from which I want to create a function, say f(x), that I will then plot. Say f(x) is a line

  f(x) = a * x + b

where the slope a is defined by

a = (Column_3 - Column_1) / 2

and b is say

b = 1.5

I've already made an array of values x as follows:

xmin = -3/2;
xmax = 3/2;

dxx = 1 / 1000;

x = xmin : dxx : xmax;

and I am able to use this array to plot the function defined by

g = (3 / 2 + tanh(x));

However, whenever I try to define an array of values for the function f(x) say by

m = vpa(a);

f = m * x + b;

plot(x, f);

I get the following error message:

??? Error using ==> plot
Conversion to double from sym is not possible

I would have assumed that m was a numerical variable, not a symbolic one, since the output of vpa is a NUMBER.

My questions are the following:

1) Is there a function in MATLAB that I can use to determine what type of variable m is, say

whatis(m)

2) How do I convert the (presumably) symbolic result

a = (Column_3 - Column_1) / 2

into a form that I can use to define an array of numerical values that I can plot.

Thanks!

- EGP

Subject: How do I determine whether a variable is numerical or symbolic?

From: Ashish Uthama

Date: 27 Oct, 2008 20:46:23

Message: 2 of 3

1. use 'whos' to manually inspect
2. I searched for is* in the doc and I think ISNUMERIC would help. 1 if
its a number 0 if its symbolic or otherwise.

> 1) Is there a function in MATLAB that I can use to determine what type
> of variable m is, say
>
> whatis(m)
>

Subject: How do I determine whether a variable is numerical or symbolic?

From: David

Date: 27 Oct, 2008 20:58:02

Message: 3 of 3

"Gerry Puckett" <egpuckett@ucdavis.edu> wrote in message <ge57lp$qai$1@fred.mathworks.com>...
> I'm using the symbolic toolbox to determine certain values; e.g.,
>
> Column_1 = int(3 / 2 + tanh(z), z, -3/2, -1/2)
> Column_2 = int(3 / 2 + tanh(z), z, -1/2, 1/2)
> Column_3 = int(3 / 2 + tanh(z), z, 1/2, 3/2)
>
> from which I want to create a function, say f(x), that I will then plot. Say f(x) is a line
>
> f(x) = a * x + b
>
> where the slope a is defined by
>
> a = (Column_3 - Column_1) / 2
>
> and b is say
>
> b = 1.5
>
> I've already made an array of values x as follows:
>
> xmin = -3/2;
> xmax = 3/2;
>
> dxx = 1 / 1000;
>
> x = xmin : dxx : xmax;
>
> and I am able to use this array to plot the function defined by
>
> g = (3 / 2 + tanh(x));
>
> However, whenever I try to define an array of values for the function f(x) say by
>
> m = vpa(a);
>
> f = m * x + b;
>
> plot(x, f);
>
> I get the following error message:
>
> ??? Error using ==> plot
> Conversion to double from sym is not possible
>
> I would have assumed that m was a numerical variable, not a symbolic one, since the output of vpa is a NUMBER.
>
> My questions are the following:
>
> 1) Is there a function in MATLAB that I can use to determine what type of variable m is, say
>
> whatis(m)
>
> 2) How do I convert the (presumably) symbolic result
>
> a = (Column_3 - Column_1) / 2
>
> into a form that I can use to define an array of numerical values that I can plot.
>
> Thanks!
>
> - EGP
>

isa(m,'sym') tests for symbolic
double(m) converts symbolic to real

dave y.

Tags for this Thread

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.

rssFeed for this Thread

Contact us at files@mathworks.com