A simple symbolic expression in Matlab

In summary, the conversation is about using logical and isAlways in Matlab to check the validity of equations and inequalities, with the reminder to use isAlways for equations that require simplification or mathematical transformations.
  • #1
Dr_Pill
41
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
  • #2
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"
 
  • #3
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.
 
  • #5
Ah, I see; he's analyzing the truthiness, not looking for a solution.
 

What is a simple symbolic expression in Matlab?

A simple symbolic expression in Matlab is a mathematical expression or equation that uses symbolic variables instead of numerical values. This allows for more flexibility and manipulation in calculations, as well as the ability to solve for variables symbolically.

How do I create a simple symbolic expression in Matlab?

To create a simple symbolic expression in Matlab, you can use the "syms" function to declare symbolic variables and then use mathematical operators (+, -, *, /) and parentheses to construct the expression. For example, "syms x y" creates the symbolic variables x and y, and "x + y" creates the expression x + y.

Can I use symbolic expressions in calculations and functions?

Yes, symbolic expressions can be used in calculations and functions just like numerical values. However, since they are symbolic, they may take longer to calculate than numerical values and may require additional commands to evaluate or simplify.

How do I solve a simple symbolic expression in Matlab?

To solve a simple symbolic expression in Matlab, you can use the "solve" function, which takes in the expression and the variable you want to solve for. For example, "solve(x^2 + 2*x + 1, x)" would solve the expression for the variable x and return the solution as a symbolic variable.

Can I convert a symbolic expression to a numerical value?

Yes, you can use the "double" or "eval" function to convert a symbolic expression to a numerical value. "double" will return a double-precision floating-point number, while "eval" will evaluate the expression at a specific value. For example, "double(x^2 + 2*x + 1)" would return the numerical value of the expression, while "eval(x^2 + 2*x + 1, x, 2)" would evaluate the expression at x=2 and return the value.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
822
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
8
Views
1K
Back
Top