How to get numerical value from symbolic variables in matlab?

1 次查看(过去 30 天)
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?

采纳的回答

Walter Roberson
Walter Roberson 2019-3-25
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.

更多回答(0 个)

产品


版本

R2015b

Community Treasure Hunt

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

Start Hunting!

Translated by