3
votes

I am trying to evaluate a convolution integral using the symbolic int() function and instead of returning a useful answer, my program is returning the integral itself. Here is my code

clc; clear;
pkg load symbolic
syms t tau Wn   % Declare symbolic variables
f = tau^2 * sin( Wn *(t-tau) );
convolution = int( f, tau, [0 t] );   % Specify tau as the integration variable
                                      % and integration limits are from 0 to t 
pretty(convolution)

The code runs, but does not return something useful. Instead of returning an answer, it returns this:

  t                       
  ⌠                       
  ⎮  2                    
  ⎮ τ ⋅sin(Wn⋅t - Wn⋅τ) dτ
  ⌡                       
  0       

i.e. the original integral with the function inside of it.

I've tried troubleshooting the problem in the following ways:

  • Copy/pasting example code from the Octave int() help page, this works and evaluates the definite integral
  • Changing the integration syntax from 0, t to [0, t] this changes nothing
  • Making variable f and storing the function there, instead of the function being inside of int(). This changes nothing

I know the symbolic package is working, because the example code returns the correct definite integral.

Thanks.

1
I can reproduce the problem. Matlab does give a result - Luis Mendo

1 Answers

0
votes

You can use eval in order to "evaluate" (duh) the integral. E.g. with your code above, I get:

octave:9> eval( convolution )
ans = (sym)
  ⎧ 2                                                   
  ⎪t    2⋅cos(Wn⋅t)    2                                
  ⎪── + ─────────── - ───  for Wn > -∞ ∧ Wn < ∞ ∧ Wn ≠ 0
  ⎨Wn         3         3                               
  ⎪         Wn        Wn                                
  ⎪                                                     
  ⎩          0                       otherwise          

Note that if you actually 'define' some of those symbols on the workspace, then these get taken into account:

octave:10> Wn = 1;   % or preferably `sym('1')` ...
octave:11> eval( convolution )
ans = (sym)
   2               
  t  + 2⋅cos(t) - 2