sympref
Set symbolic settings
Syntax
Description
sets the symbolic setting oldVal
= sympref(pref
,value
)pref
to
value
and returns the previous value of the setting to
oldVal
. You can set the setting to its default value
using sympref(pref,'default')
.
Symbolic settings can affect the computation of the symbolic functions
fourier
, ifourier
, and
heaviside
, and the display format of symbolic
output.
Examples
The Fourier transform of is
where and are parameters with the default values 1 and –1, respectively. Other common values for are and , and other common values for are , , and .
Find the Fourier transform of sin(t)
with default c
and s
parameters.
syms t w F = fourier(sin(t),t,w)
F =
Find the same Fourier transform with and . Set these parameter values by changing the 'FourierParameters'
setting. Represent exactly by using sym
. Specify the values of c
and s
as the vector [1/(2*sym(pi)) 1]
. Store the previous values returned by sympref
so that you can restore them later.
oldVal = sympref('FourierParameters',[1/(2*sym(pi)) 1])
oldVal =
F = fourier(sin(t),t,w)
F =
The settings that you set using sympref
persist through your current and future MATLAB® sessions. Restore the previous values of c
and s
to oldVal
.
sympref('FourierParameters',oldVal);
Alternatively, you can restore the default values of c
and s
by specifying the 'default'
option.
sympref('FourierParameters','default');
In Symbolic Math Toolbox™, the default value of the Heaviside function at the origin is 1/2. Return the value of heaviside(0)
. Find the Z-transform of heaviside(x)
for this default value of heaviside(0)
.
syms x
H = heaviside(sym(0))
H =
Z = ztrans(heaviside(x))
Z =
Other common values for the Heaviside function at the origin are 0 and 1. Set heaviside(0)
to 1
by changing the 'HeavisideAtOrigin'
setting. Store the previous value returned by sympref
so that you can restore it later.
oldVal = sympref('HeavisideAtOrigin',1)
oldVal =
Check if the new value of heaviside(0)
is 1. Find the Z-transform of heaviside(x)
for this value.
H = heaviside(sym(0))
H =
Z = ztrans(heaviside(x))
Z =
The new output of heaviside(0)
modifies the output of ztrans
.
The settings that you set using sympref
persist through your current and future MATLAB® sessions. Restore the previous value of heaviside(0)
to oldVal
.
sympref('HeavisideAtOrigin',oldVal);
Alternatively, you can restore the default value of 'HeavisideAtOrigin'
by specifying the 'default'
option.
sympref('HeavisideAtOrigin','default');
By default, symbolic expressions in live scripts are displayed in abbreviated output format, and typeset in mathematical notation. You can turn off abbreviated output format and typesetting using symbolic settings.
Create a symbolic expression and return the output, which is abbreviated by default.
syms a b c d x f = a*x^3 + b*x^2 + c*x + d; outputAbbrev = sin(f) + cos(f) + tan(f) + log(f) + 1/f
outputAbbrev =
Turn off abbreviated output format by setting 'AbbreviateOutput'
to false
. Redisplay the expression.
sympref('AbbreviateOutput',false);
outputLong = sin(f) + cos(f) + tan(f) + log(f) + 1/f
outputLong =
Create another symbolic expression and return the output, which is typeset in mathematical notation by default. Turn off rendered output and use ASCII output instead by setting 'TypesetOutput'
to false
. First, show the typeset output.
syms a b c d x f = exp(a^b)+pi
f =
Turn off typesetting by setting 'TypesetOutput'
to false
. Redisplay the expression.
sympref('TypesetOutput',false);
f = exp(a^b)+pi
f = pi + exp(a^b)
The settings that you set using sympref
persist through your current and future MATLAB® sessions. Restore the default values of 'AbbreviateOutput'
and 'TypesetOutput'
by specifying the 'default'
option.
sympref('AbbreviateOutput','default'); sympref('TypesetOutput','default');
Display symbolic results in floating-point output format, that is the short, fixed-decimal format with 4 digits after the decimal point.
Create a quadratic equation.
syms x
eq = x^2 - 2e3/sym(pi)*x + 0.5 == 0
eq =
Find the solutions of the equation using solve
.
sols = solve(eq,x)
sols =
Set the 'FloatingPointOutput'
setting to true
. Display the quadratic equation and its solutions in floating-point format.
sympref('FloatingPointOutput',true);
eq
eq =
sols
sols =
The floating-point format displays each symbolic number in the short, fixed-decimal format with 4 digits after the decimal point. The 'FloatingPointOutput'
setting does not affect the floating-point precision in a symbolic computation. To compute symbolic numbers using floating-point arithmetic, use the vpa
function.
Now restore the default value of 'FloatingPointOutput'
by specifying the 'default'
option. Compute the floating-point approximation of the solutions in 8 significant digits using vpa
.
sympref('FloatingPointOutput','default'); sols = vpa(sols,8)
sols =
Create a symbolic polynomial expression consisting of multiple variables. Display the polynomial in the default order.
syms x y a b p1 = b^2*x^2 + a^2*x + y^3 + 2
p1 =
The default option sorts the output in alphabetical order, without distinguishing the different symbolic variables in each monomial term.
Now display the same polynomial in ascending order by setting 'PolynomialDisplayStyle'
to 'ascend'
.
sympref('PolynomialDisplayStyle','ascend'); p1
p1 =
The 'ascend'
option sorts the output in ascending order based on the importance of the variables. Here, the most important variable x
with the highest order in a monomial term is displayed last.
Display the polynomial in descending order by setting 'PolynomialDisplayStyle'
to 'descend'
.
sympref('PolynomialDisplayStyle','descend'); p1
p1 =
The settings that you set using sympref
persist through your current and future MATLAB® sessions. Restore the default value of 'PolynomialDisplayStyle'
by specifying the 'default'
option.
sympref('PolynomialDisplayStyle','default');
By default, a symbolic matrix in live scripts is set in parentheses (round brackets). You can specify the use of square brackets instead by using sympref
.
Create a symbolic matrix consisting of symbolic variables and numbers.
syms x y A = [x*y, 2; 4, y^2]
A =
Display the matrix with square brackets by setting 'MatrixWithSquareBrackets'
to true
.
sympref('MatrixWithSquareBrackets',true);
A
A =
The settings that you set using sympref
persist through your current and future MATLAB® sessions. Restore the default value by specifying the 'default'
option.
sympref('MatrixWithSquareBrackets','default');
Instead of saving and restoring individual settings one by one, you can use sympref
to save and restore all symbolic settings simultaneously.
Return a structure containing the values of all symbolic settings by using sympref()
.
oldPrefs = sympref()
oldPrefs = struct with fields:
FourierParameters: [1 -1]
HeavisideAtOrigin: 1/2
AbbreviateOutput: 1
TypesetOutput: 1
FloatingPointOutput: 0
PolynomialDisplayStyle: 'default'
MatrixWithSquareBrackets: 0
Access the value of each symbolic setting by addressing the field of the structure. Alternatively, you can use the command sympref(pref)
.
val1 = oldPrefs.FourierParameters
val1 =
val2 = oldPrefs.HeavisideAtOrigin
val2 =
val3 = sympref('FourierParameters')
val3 =
To modify multiple symbolic settings simultaneously, you can create a structure prefs
that contains the setting values. Use the command sympref(prefs)
to set multiple settings.
prefs.FourierParameters = [1/(2*sym(pi)) 1]
prefs = struct with fields:
FourierParameters: [1/(2*pi) 1]
prefs.HeavisideAtOrigin = 1
prefs = struct with fields:
FourierParameters: [1/(2*pi) 1]
HeavisideAtOrigin: 1
sympref(prefs);
Because symbolic settings persist through your current and future MATLAB® sessions, you need to restore your previous settings. Restore the saved settings using sympref(oldPrefs)
.
sympref(oldPrefs);
Alternatively, you can set all symbolic settings to their default values by specifying the 'default'
option.
sympref('default');
Input Arguments
Symbolic setting, specified as a character vector or string. The value options for each symbolic setting follow.
setting | Value | Description |
---|---|---|
| Two-element row vector Default:
| Set the values of the parameters c and s in the Fourier transform:
|
| Scalar value, specified as a numeric or symbolic number. Default:
| Set the value of the Heaviside function
|
| Logical value (boolean). Default:
logical | Specify whether or not to use abbreviated output format of symbolic variables and expressions in Live Scripts. |
| Logical value (boolean). Default:
logical | Typeset or use ASCII characters for the output of symbolic variables and expressions in Live Scripts. |
| Logical value (boolean). Default:
logical | Specify whether or not to display symbolic results in floating-point output format. The
|
| Character vector or scalar string, specified as
Default:
| Display a symbolic polynomial in default, ascending, or descending order.
|
| Logical value (boolean). Default:
logical | Set matrices in round brackets or parentheses (round brackets) in Live Scripts. |
Value of symbolic setting, specified as 'default'
or a
valid value of the specified setting pref
.
Symbolic settings, specified as a structure array. You can set multiple settings by declaring the field names and the valid setting values.
Output Arguments
Value of symbolic setting, returned as a valid value.
oldVal
represents the existing value of the setting
pref
before the call to
sympref
.
All symbolic settings, returned as a structure array.
oldPrefs
represent the existing values of all
settings before the call to sympref
.
Tips
The
clear
command does not reset or affect symbolic settings. Usesympref
to manipulate symbolic settings.The symbolic settings you set using
sympref
also determine the output generated by thelatex
andmathml
functions.The
'FloatingPointOutput'
setting affects only the output display format of symbolic numbers. To change the output display format of numeric numbers, use theformat
function. To compute symbolic numbers using floating-point precision, use thevpa
ordigits
functions.
Version History
Introduced in R2015aThe sympref
function accepts the following settings:
'FloatingPointOutput'
displays symbolic numbers in short fixed-decimal format.'PolynomialDisplayStyle'
displays polynomials in ascending or descending order.'MatrixWithSquareBrackets'
displays symbolic matrices with square brackets in Live Scripts.
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)