sympref
Set symbolic preferences
Syntax
Description
sets the symbolic preference oldVal
= sympref(pref
,value
)pref
to
value
and returns the previous value of the preference
to oldVal
. You can set the preference to its default value
using sympref(pref,'default')
.
Symbolic preferences can affect the computation of the symbolic functions
fourier
, ifourier
, and
heaviside
, and the display format of symbolic
output.
Examples
Change Parameter Values of Fourier Transform
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 the parameter values by using the 'FourierParameters'
preference. 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 preferences 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');
Change Value of Heaviside Function at Origin
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
using the 'HeavisideAtOrigin'
preference. 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 preferences 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');
Modify Display of Symbolic Expressions in Live Scripts
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 preferences.
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 the 'AbbreviateOutput'
preference 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 the 'TypesetOutput'
preference to false
. First, show the typeset output.
syms a b c d x f = exp(a^b)+pi
f =
Turn off typesetting by setting the 'TypesetOutput'
preference to false
. Redisplay the expression.
sympref('TypesetOutput',false);
f = exp(a^b)+pi
f = pi + exp(a^b)
The preferences 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 Format
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'
preference 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. Setting the 'FloatingPointOutput'
preference 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 =
Modify Output Order of Symbolic Polynomial
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 the preference '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 the 'PolynomialDisplayStyle'
preference to 'descend'
.
sympref('PolynomialDisplayStyle','descend'); p1
p1 =
The preferences 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');
Modify Display of Symbolic Matrix in Live Scripts
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 the 'MatrixWithSquareBrackets'
preference to true
.
sympref('MatrixWithSquareBrackets',true);
A
A =
The preferences you set using sympref
persist through your current and future MATLAB® sessions. Restore the default value by specifying the 'default'
option.
sympref('MatrixWithSquareBrackets','default');
Save and Restore All Symbolic Preferences
Instead of saving and restoring individual preferences one by one, you can use sympref
to save and restore all symbolic preferences simultaneously.
Return a structure containing the values of all symbolic preferences 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 preference 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 preferences simultaneously, you can create a structure prefs
that contains the preference values. Use the command sympref(prefs)
to set multiple preferences.
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 preferences persist through your current and future MATLAB® sessions, you need to restore your previous preferences. Restore the saved preferences using sympref(oldPrefs)
.
sympref(oldPrefs);
Alternatively, you can set all symbolic preferences to their default values by specifying the 'default'
option.
sympref('default');
Input Arguments
pref
— Symbolic preference
character vector | string
Symbolic preference, specified as a character vector or string. The value options for each symbolic preference follow.
Preference | 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
— Value of symbolic preference
'default'
(default) | valid value
Value of symbolic preference, specified as 'default'
or
a valid value of the specified preference pref
.
prefs
— Symbolic preferences
structure array
Symbolic preferences, specified as a structure array. You can set multiple preferences by declaring the field names and the valid preference values.
Output Arguments
oldVal
— Value of symbolic preference
valid value
Value of symbolic preference, returned as a valid value.
oldVal
represents the existing value of the
preference pref
before the call to
sympref
.
oldPrefs
— All symbolic preferences
structure array
All symbolic preferences, returned as a structure array.
oldPrefs
represent the existing values of all
preferences before the call to sympref
.
Tips
The
clear
command does not reset or affect symbolic preferences. Usesympref
to manipulate symbolic preferences.The symbolic preferences you set using
sympref
also determine the output generated by thelatex
andmathml
functions.Setting the
'FloatingPointOutput'
preference 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 R2015aR2019a: Additional preferences to change display of symbolic output
The sympref
function accepts the following preferences:
'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-Befehl
Sie haben auf einen Link geklickt, der diesem MATLAB-Befehl entspricht:
Führen Sie den Befehl durch Eingabe in das MATLAB-Befehlsfenster aus. Webbrowser unterstützen keine MATLAB-Befehle.
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)