DMelt:JMathlab/3 Symbolic Variables

From HandWiki

Symbolic Variables

In contrast to the examples Octave and Matlab, Jasymca integrates numeric and symbolic datatypes at the core of the program; symbolic math is not treated as an add-on. This means that with few exceptions most operations accept any mixture of numeric and symbolic arguments using the same commands and command syntax.

Symbolic variables should not be confused with variables as discussed until now. These latter variables serve as address for an object in memory (the "environment"), while symbolic variables are algebraic objects on their own. That means if x is a conventional variable, entering x in the text input field makes Jasymca search in the environment for the corresponding object, which then replaces x. If however x is a symbolic variable, the same action will lead to the creation of a first-degree polynomial with variable x and coefficients 1 and 0.

In Octave-mode, each symbolic variable x must be declared as symbolic by entering syms x before using it. The command clear x deletes the symbolic (actually any) variable x.

>> x=3;             % nonsymbolic variable
>> x^2+3-2*sin(x)   % placeholder for '3'
ans = 11.718        
>> syms x           % symbolic variable
>> x^2+3-2*sin(x)   % create function
ans = -2*sin(x)+(x^2+3)


Variables are declared by supplying a name and value in the format name=value. The name can be any character sequence. With the exception of the first character it may also contain numbers. The value is any number or expression.

>> x=24+3i
x = 24+3i

Some variables are predefined (like pi). The last previous result of a calculation is stored in the variable ans. All variables are displayed by the command who. Single variables can be deleted by entering clear variable.

It is possible to define variables whose value is a function. In this case the function's name must be preceded by the character $ to suppress evaluation. These variables can be used like the function they stand for. For example, who dislikes the builtin function realpart(x)'s name can shorten it to the Matlab-version:

>> real=$realpart
>> real(24+3i)
ans = 24

Here is an example of calculation of the skin surface of your body from height $h$ and

weight W using DuBois' formula: 

>> h=182; W=71;     
>> A=h^0.725*W^0.425*71.84e-4
A = 1.9129