MATLAB A simple symbolic expression in Matlab

  • Thread starter Thread starter Dr_Pill
  • Start date Start date
  • Tags Tags
    Expression Matlab
AI Thread Summary
The discussion revolves around checking the mathematical equivalence of the expressions x²-1 and (x+1)(x-1) using MATLAB. The user, a beginner, finds that the logical function returns 0, indicating that the expressions are not considered equivalent by MATLAB. A key point raised is that the logical function may not be suitable for checking equations that require simplification or transformations, which can lead to unexpected results. Instead, the use of the isAlways function is recommended for validating such conditions, as it checks if an expression holds true for all possible values of the symbolic variable. The conversation highlights the importance of understanding MATLAB's symbolic toolbox and the appropriate functions for different types of mathematical checks.
Dr_Pill
Messages
41
Reaction score
0
I tried to check

x²-1 = (x+1)(x--1)

So I did the following:

syms x

f = x^2 - 1
g = (x+1)*(x-1)

logical(f == g)

Matlab returns 0.

Any suggestions? :)

(Matlab beginner by the way)
 
Physics news on Phys.org
Maybe this? From

http://www.mathworks.com/help/symbolic/logical.html

"Do not use logical to check equations and inequalities that require simplification or mathematical transformations. For such equations and inequalities, logical might return unexpected results. For example, logical does not recognize mathematical equivalence of these expressions:
...
To test the validity of equations and inequalities that require simplification or mathematical transformations, use isAlways:

isAlways(sin(x)/cos(x) == tan(x))
ans = 1"
 
Dr_Pill said:
I tried to check

x²-1 = (x+1)(x--1)

So I did the following:
Matlab returns 0.

Any suggestions? :)

(Matlab beginner by the way)

If I'm interpreting the result correctly,
0 is a legit answer, if x = 0, f = -1 and g= -1, so f=g.

Never used the symbolic toolbox, just thought I'd point that out.
 
Ah, I see; he's analyzing the truthiness, not looking for a solution.
 

Similar threads

Replies
8
Views
2K
Replies
2
Views
3K
Replies
5
Views
3K
Replies
2
Views
3K
Replies
5
Views
2K
Replies
4
Views
3K
Back
Top