Algebraic simplification - MATLAB simplify - MathWorks Deutschland (2024)

Algebraic simplification

collapse all in page

Syntax

S = simplify(expr)

S = simplify(expr,Name,Value)

Description

example

S = simplify(expr) performs algebraic simplification of expr. If expr is a symbolic vector or matrix, this function simplifies each element of expr.

example

S = simplify(expr,Name,Value) performs algebraic simplification of expr using additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Simplify Expressions

Open Live Script

Simplify these symbolic expressions:

syms x a b cS = simplify(sin(x)^2 + cos(x)^2)
S =1
S = simplify(exp(c*log(sqrt(a+b))))
S =a+bc/2

Simplify Matrix Elements

Open Live Script

Call simplify for this symbolic matrix. When the input argument is a vector or matrix, simplify tries to find a simpler form of each element of the vector or matrix.

syms xM = [(x^2 + 5*x + 6)/(x + 2), sin(x)*sin(2*x) + cos(x)*cos(2*x);(exp(-x*1i)*1i)/2 - (exp(x*1i)*1i)/2, sqrt(16)];S = simplify(M)
S =

(x+3cos(x)sin(x)4)

Get Simpler Results for Logarithms and Powers

Open Live Script

Simplify a symbolic expression that contains logarithms and powers. By default, simplify does not combine powers and logarithms because combining them is not valid for generic complex values.

syms xexpr = (log(x^2 + 2*x + 1) - log(x + 1))*sqrt(x^2);S = simplify(expr)
S =-log(x+1)-log(x+12)x2

To apply the simplification rules that allow the simplify function to combine powers and logarithms, set 'IgnoreAnalyticConstraints' to true:

S = simplify(expr,'IgnoreAnalyticConstraints',true)
S =xlog(x+1)

Open Live Script

Simplify this expression:

syms xexpr = ((exp(-x*1i)*1i) - (exp(x*1i)*1i))/(exp(-x*1i) + exp(x*1i));S = simplify(expr)
S =

-e2xii-ie2xi+1

By default, simplify uses one internal simplification step. You can get different, often shorter, simplification results by increasing the number of simplification steps:

S10 = simplify(expr,'Steps',10)
S10 =

2ie2xi+1-i

S30 = simplify(expr,'Steps',30)
S30 =

cos(x)-sin(x)iicos(x)-i

S50 = simplify(expr,'Steps',50)
S50 =tan(x)

If you are unable to return the desired result, try alternate simplification functions. See Choose Function to Rearrange Expression.

Get Equivalent Results for Symbolic Expression

Open Live Script

Get equivalent results for a symbolic expression by setting the value of 'All' to true.

syms xexpr = cos(x)^2 - sin(x)^2;S = simplify(expr,'All',true)
S =

(cos(2x)cos(x)2-sin(x)2)

Increase the number of simplification steps to 10. Find the other equivalent results for the same expression.

S = simplify(expr,'Steps',10,'All',true)
S =

(cos(2x)1-2sin(x)22cos(x)2-1cos(x)2-sin(x)2cot(2x)sin(2x)e-2xi2+e2xi2)

Separate Real and Imaginary Parts

Open Live Script

Attempt to separate real and imaginary parts of an expression by setting the value of 'Criterion' to 'preferReal'.

syms xf = (exp(x + exp(-x*1i)/2 - exp(x*1i)/2)*1i)/2 -... (exp(-x - exp(-x*1i)/2 + exp(x*1i)/2)*1i)/2;S = simplify(f,'Criterion','preferReal','Steps',100)
S =sin(sin(x))cosh(x)+cos(sin(x))sinh(x)i

If 'Criterion' is not set to 'preferReal', then simplify returns a shorter result but the real and imaginary parts are not separated.

S = simplify(f,'Steps',100)
S =sin(sin(x)+xi)

When you set 'Criterion' to 'preferReal', the simplifier disfavors expression forms where complex values appear inside subexpressions. In nested subexpressions, the deeper the complex value appears inside an expression, the least preference this form of an expression gets.

Avoid Imaginary Terms in Exponents

Open Live Script

Attempt to avoid imaginary terms in exponents by setting 'Criterion' to 'preferReal'.

Show this behavior by simplifying a complex symbolic expression with and without setting 'Criterion' to 'preferReal'. When 'Criterion' is set to 'preferReal', then simplify places the imaginary term outside the exponent.

expr = sym(1i)^(1i+1);withoutPreferReal = simplify(expr,'Steps',100)
withoutPreferReal =

-112+12i

withPreferReal = simplify(expr,'Criterion','preferReal','Steps',100)
withPreferReal =

e-π2i

Simplify Units

Open Live Script

Simplify expressions containing symbolic units of the same dimension by using simplify.

u = symunit;expr = 300*u.cm + 40*u.inch + 2*u.m;S = simplify(expr)
S =

752125m"meter - a physical unit of length."

simplify automatically chooses the unit to rewrite into. To choose a specific unit, use rewrite.

Get Simpler Result by Expanding Expression

Open Live Script

In most cases, to simplify a symbolic expression using Symbolic Math Toolbox™, you only need to use the simplify function. But for some large and complex expressions, you can obtain a faster and simpler result by using the expand function before applying simplify.

For instance, this workflow gives better results when finding the determinant of a matrix that represents the Kerr metric [1]. Declare the parameters of the Kerr metric.

syms theta real;syms r rs a real positive;

Define the matrix that represents the Kerr metric.

rho = sqrt(r^2 + a^2*cos(theta)^2);delta = r^2 + a^2 - r*rs;g(1,1) = - (1 - r*rs/rho^2);g(1,4) = - (rs*a*r*sin(theta)^2)/rho^2;g(4,1) = - (rs*a*r*sin(theta)^2)/rho^2;g(2,2) = rho^2/delta;g(3,3) = rho^2;g(4,4) = (r^2 + a^2 + rs*a^2*r*sin(theta)^2/rho^2)*sin(theta)^2;

Evaluate the determinant of the Kerr metric.

det_g = det(g)
det_g =

-sin(θ)2a6cos(θ)4+a4r2cos(θ)4+2a4r2cos(θ)2+rsa4rcos(θ)2sin(θ)2-rsa4rcos(θ)2+2a2r4cos(θ)2+a2r4-rsa2r3cos(θ)2+rsa2r3sin(θ)2-rsa2r3+r6-rsr5a2+r2-rsr

Simplify the determinant using the simplify function.

D = simplify(det_g)
D =-sin(θ)2a2cos(θ)2+r2-a2sin(θ)2+a2+r2

Instead, flatten the expression using the expand function, and then apply the simplify function. The result is simpler with this extra step.

D = simplify(expand(det_g))
D =-sin(θ)2-a2sin(θ)2+a2+r22

Input Arguments

collapse all

exprInput expression
symbolic expression | symbolic function | symbolic vector | symbolic matrix

Input expression, specified as a symbolic expression, function, vector, or matrix.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'Seconds',60 limits the simplificationprocess to 60 seconds.

AllOption to return equivalent results
false (default) | true

Option to return equivalent results, specified as the comma-separated pair consisting of 'All' and either of the two logical values. When you use this option, the input argument expr must be a scalar.

falseUse the default option to return only the final simplification result.
trueReturn a column vector of equivalent results for the input expression. You can use this option along with the 'Steps' option to obtain alternative expressions in the simplification process.

CriterionSimplification criterion
'default' (default) | 'preferReal'

Simplification criterion, specified as the comma-separated pairconsisting of 'Criterion' and one of these charactervectors.

'default'Use the default (internal) simplification criteria.
'preferReal'Favor the forms of S containing real valuesover the forms containing complex values. If any form of S containscomplex values, the simplifier disfavors the forms where complex valuesappear inside subexpressions. In case of nested subexpressions, thedeeper the complex value appears inside an expression, the least preferencethis form of an expression gets.

IgnoreAnalyticConstraintsSimplification rules
false (default) | true

Simplification rules, specified as the comma-separated pairconsisting of 'IgnoreAnalyticConstraints' and oneof these values.

falseUse strict simplification rules. simplify always returns results that are analytically equivalent to the initial expression.
trueApply purely algebraic simplifications to expressions. Setting IgnoreAnalyticConstraints to true can give you simpler solutions, which could lead to results not generally valid. In other words, this option applies mathematical identities that are convenient, but the results might not hold for all possible values of the variables. In some cases, the results might not be equivalent to the initial expression. For details, see Algorithms.

SecondsTime limit for the simplification process
Inf (default) | positive number

Time limit for the simplification process, specified as thecomma-separated pair consisting of 'Seconds' anda positive value that denotes the maximal time in seconds.

StepsNumber of simplification steps
1 (default) | positive number

Number of simplification steps, specified as the comma-separatedpair consisting of 'Steps' and a positive valuethat denotes the maximal number of internal simplification steps.Note that increasing the number of simplification steps can slow downyour computations.

simplify(expr,'Steps',n) is equivalent to simplify(expr,n), where n is the number of simplification steps.

Tips

  • Simplification of mathematical expression is not aclearly defined subject. There is no universal idea as to which formof an expression is simplest. The form of a mathematical expressionthat is simplest for one problem might be complicated or even unsuitablefor another problem.

Algorithms

When you use IgnoreAnalyticConstraints, then simplify follows some of these rules:

  • log(a) + log(b)=log(a·b) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:

    (a·b)c=ac·bc.

  • log(ab)=b·log(a) for all values of a and b. In particular, the following equality is valid for all values of a, b, and c:

    (ab)c=ab·c.

  • If f and g are standard mathematical functions and f(g(x))=x for all small positive numbers, f(g(x))=x is assumed to be valid for all complex values of x. In particular:

    • log(ex)=x

    • asin(sin(x))=x, acos(cos(x))=x, atan(tan(x))=x

    • asinh(sinh(x))=x, acosh(cosh(x))=x, atanh(tanh(x))=x

    • Wk(x·ex)=x for all branch indices k of the Lambert W function.

References

[1] Zee, A. Einstein Gravity in a Nutshell. Princeton: Princeton University Press, 2013.

Version History

Introduced before R2006a

See Also

Functions

  • collect | combine | expand | factor | horner | numden | rewrite | simplifyFraction

Live Editor Tasks

  • Simplify Symbolic Expression

Topics

  • Simplify Symbolic Expressions
  • Choose Function to Rearrange Expression
  • Simplify Symbolic Expressions Using Live Editor Task

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.

Algebraic simplification - MATLAB simplify- MathWorks Deutschland (1)

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:

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
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Algebraic simplification - MATLAB simplify
- MathWorks Deutschland (2024)

FAQs

How to simplify an algebraic expression in Matlab? ›

S = simplify( expr ) performs algebraic simplification of expr . If expr is a symbolic vector or matrix, this function simplifies each element of expr . S = simplify( expr , Name,Value ) performs algebraic simplification of expr using additional options specified by one or more Name,Value pair arguments.

What is the pretty command in Matlab? ›

pretty( X ) prints X in a plain-text format that resembles typeset mathematics. For true typeset rendering, use Live Scripts instead. See What Is a Live Script or Function?

What is simplify fraction in Matlab? ›

simplifyFraction( expr ) simplifies the rational expression expr such that the numerator and denominator have no divisors in common. simplifyFraction( expr ,'Expand',true) expands the numerator and denominator of the resulting simplified fraction as polynomials without factorization.

What is Syms in Matlab? ›

syms lists the names of all symbolic scalar variables, functions, matrix variables, matrix functions, and arrays in the MATLAB workspace. example. S = syms returns a cell array of the names of all symbolic scalar variables, functions, matrix variables, matrix functions, and arrays.

How do you simplify algebraic expressions quickly? ›

How to simplify expressions. To simplify expressions first expand any brackets, next multiply or divide any terms and use the laws of indices if necessary, then collect like terms by adding or subtracting and finally rewrite the expression.

What app can I use to simplify algebraic expressions? ›

Wolfram|Alpha can be used as a simplification calculator to simplify polynomials, Booleans, numbers, rational functions and many other math objects.

What is the %% used for in MATLAB? ›

Two percent signs, %% , serve as a cell delimiter as described in Create and Run Sections in Code. Add a comment to a block of code: % The purpose of this loop is to compute % the value of ...

How to write algebraic expressions in MATLAB? ›

Basic Algebraic Operations
  1. syms t G = [cos(t) sin(t); -sin(t) cos(t)] create this transformation matrix.
  2. G = [ cos(t), sin(t)] [ -sin(t), cos(t)] ...
  3. A = G*G. ...
  4. A = G^2. ...
  5. A = [ cos(t)^2 - sin(t)^2, 2*cos(t)*sin(t)] [ -2*cos(t)*sin(t), cos(t)^2 - sin(t)^2] ...
  6. A = simplify(A) ...
  7. A = [ cos(2*t), sin(2*t)] [ -sin(2*t), cos(2*t)] ...
  8. I = G.'

What does eye () do in MATLAB? ›

I = eye( n ) returns an n -by- n identity matrix with ones on the main diagonal and zeros elsewhere.

What is simplify mesh in MATLAB? ›

simplify( mesh ) simplifies the surface mesh mesh by using quadric decimation. simplify( mesh ,Name=Value) specifies options using one or more name-value arguments. For example, SimplificationMethod="vertex-clustering" simplifies the surface mesh by using the vertex-clustering method.

What is an example of simplify in math? ›

For example, 1/2 (x + 4) can be simplified as x/2 + 2. Let us take one more example to understand it. Example: Simplify the expression: 3/4x + y/2 (4x + 7). By using the distributive property, the given expression can be written as 3/4x + y/2 (4x) + y/2 (7).

What is == in MATLAB? ›

Description. example. A == B returns a logical array or a table of logical values with elements set to logical 1 ( true ) where inputs A and B are equal; otherwise, the element is logical 0 ( false ).

What does Dirac mean in MATLAB? ›

dirac returns floating-point results for numeric arguments that are not symbolic objects. dirac acts element-wise on nonscalar inputs. The input arguments x and n must be vectors or matrices of the same size, or else one of them must be a scalar.

What is ABS in MATLAB? ›

abs( z ) returns the absolute value (or complex modulus) of z . Because symbolic variables are assumed to be complex by default, abs returns the complex modulus (magnitude) by default. If z is an array, abs acts element-wise on each element of z .

How do you simplify an algebraic formula? ›

Algebraic expressions can be simplified by multiplying out the brackets and collecting like terms, or by factorising with a common factor. Straight line gradients can be calculated using a formula.

How do you simplify algebraic notation? ›

An expression can be simplified by collecting like terms. Like terms are those which contain the same letter symbol and equal powers. As 2 + 2 + 2 can be written as 3 x 2, a + a + a can be written as 3 x a. However, with algebraic notation, multiply and division symbols are not included.

How do you solve a simple equation in MATLAB? ›

Solve an Equation

If eqn is an equation, solve(eqn, x) solves eqn for the symbolic variable x . Use the == operator to specify the familiar quadratic equation and solve it using solve . solx is a symbolic vector containing the two solutions of the quadratic equation.

References

Top Articles
Latest Posts
Article information

Author: Clemencia Bogisich Ret

Last Updated:

Views: 6265

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Clemencia Bogisich Ret

Birthday: 2001-07-17

Address: Suite 794 53887 Geri Spring, West Cristentown, KY 54855

Phone: +5934435460663

Job: Central Hospitality Director

Hobby: Yoga, Electronics, Rafting, Lockpicking, Inline skating, Puzzles, scrapbook

Introduction: My name is Clemencia Bogisich Ret, I am a super, outstanding, graceful, friendly, vast, comfortable, agreeable person who loves writing and wants to share my knowledge and understanding with you.