Symbolic Calculation to Numeric value for limit of an integral

1 view (last 30 days)
Hi, I've got a problem trying to evaluate numerically a symbolic expression, which by the way should represent the power of a signal.
I run my script and as a result I get the symbolic formula I am trying to solve; when I apply "vpa" I obtain the same result, instead with "eval" or "feval" there will occur errors.
Here the functions I use, potenza and fmodulsquared:
function [y] = potenza (signal)
hMod = @fmodulsquared;
hModsign = @(t) hMod(signal(t));
syms D;
resultIntegral = (int( hModsign, -D/2 , +D/2 ))./D;
y = limit(resultIntegral,D,+Inf);
end
function z = fmodulsquared(x)
z = abs(x).^2 ;
end
Now, running this script -which I use to test the function potenza - :
signal = @(t) -3*(sin((t-5/2)/3));
power = potenza(signal);
fprintf("La potenza del segnale è: %s \n", power);
vpa(power)
I get :
La potenza del segnale è: limit(int(9*abs(sin(t/3 - 5/6))^2, t, -D/2, D/2)/D, D, Inf)
ans =
limit(int(9*abs(sin(t/3 - 5/6))^2, t, -D/2, D/2)/D, D, Inf)
using eval instead of vpa I get:
Error using evalin
Unrecognized function or variable 't'.
Error in sym/eval (line 14)
s =
evalin('caller',vectorize(map2mat(char(x))));
  2 Comments
Nicola Scrof
Nicola Scrof on 1 Apr 2020
I am sorry, I forgot it when I pasted the script, now you can see it. Thank you very much.

Sign in to comment.

Accepted Answer

darova
darova on 1 Apr 2020
Look at your signal
t = linspace(0,100);
signal = @(t) -3*(sin((t-5/2)/3));
area(t,signal(t))
axis equal
It never ends! Integral is area under the curve
  3 Comments
Nicola Scrof
Nicola Scrof on 1 Apr 2020
Thank you for your help. I have found the solution, which is to divide by D before integrating! In this way, I get the result I wanted, as shown in the picture .

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!