Clear Filters
Clear Filters

How to get numerical value from symbolic variables in matlab?

1 view (last 30 days)
I am studying energy and power signals in MATLAB from the book "Signals & systems laboratory with MATLAB". I am trying to implement the example code at top of page123
code is follow:
syms t T
x=heaviside(t)-heaviside(t-1);
d=int(abs(x)^2,t,-T,T);
Px=limit((1/(2*T))*d,T,inf)
Ex=limit(d,T,inf)
I am expecting a result in numeric form, as shown in book to be Px=0 and Ex=1, but when I run my code, I get the result as a big equation as follows:
Px=limit(int(abs(heaviside(t) - heaviside(t - 1))^2, t, -T, T)/T, T == Inf)/2
Ex=limit(int(abs(heaviside(t) - heaviside(t - 1))^2, t, -T, T), T == Inf, Real)
How can I get a numeric result?

Accepted Answer

Walter Roberson
Walter Roberson on 25 Mar 2019
MATLAB is having trouble with the abs(x)^2 layer.
We as human(-ish)es can analyze and see that in context, the input arguments are always going to be real valued. With real-valued arguments, abs(x)^2 is going to be the same as x^2 . If you change to x^2 instead of abs(x)^2 then you will get a definite result.

More Answers (0)

Products


Release

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!