bugGNU Octave - Bugs: bug #56069, [octave forge] (symbolic) Laplace...

 
 

bug #56069: [octave forge] (symbolic) Laplace transform of sin(w*t) gives wrong value

Submitter:  None
Submitted:  Thu 04 Apr 2019 03:57:48 AM UTC
   
 
Category:  Octave Package Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  None
Originator Name:  Daniel Connors Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 5.1.0
Operating System:  * Microsoft Windows Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Sun 07 Apr 2019 05:04:06 AM UTC, comment #8: 

Thanks Dan for confirming.  I will go ahead and merge those changes.

@Mike or others: this issue can now be closed.

Colin Macdonald <cbm>
Sun 07 Apr 2019 02:19:40 AM UTC, comment #7: 

Colin,
 
I installed the two updates, laplace.m and ilaplace.m and now I get the expected result when I try:  laplace(sin(w*t)).  I appreciate the quick responses I got from you and Mike. 

I have been encouraging my students to use Octave for their circuit analysis work.  They are finding that the symbolic package and the control package can be very useful (and fun) to use.

Thanks for your support of the symbolic package.

Dan

Anonymous
Fri 05 Apr 2019 05:52:57 AM UTC, comment #6: 

I've posted a fix for this
https://github.com/cbm755/octsympy/pull/958

Daniel: would you mind reviewing that, make sure the docs sound ok?  Download the code and try it if you want.

Colin Macdonald <cbm>
Thu 04 Apr 2019 07:07:47 PM UTC, comment #5: 

@cbm I did some limited testing in Matlab's online test feature, and I think you're right, if the expression contains 't', it uses that, if not it falls back to 'symvar' logic.

Mike Miller <mtmiller>
Group Member
Thu 04 Apr 2019 10:50:42 AM UTC, comment #4: 

Mike and Colin,
 
Thank you for your suggestions and recommendations.  I will go with


laplace(sin(w*t), t, s)


That works!

When I encountered the problem, I couldn't figure out for laplace(sin(w*t)) how the symbolic processor knew which variable was the integration variable and which was the complex frequency -- it didn't occur to me that there would be an alphabetical rule that caused my "a" example to work differently than my "w" example.  I like the recommendation you gave --- it's clean and it explicitly sets the proper variables.

Thank you for your help.

Anonymous
Thu 04 Apr 2019 07:25:24 AM UTC, comment #3: 

It is valid.  I originally thought symvar made more sense b/c that's how other places do this magical lets-guess-the-independent-variable game...

In the code there are comments like:

t = symvar(f, 1);  % note SMT does something different, prefers t
...
% matlab SMT prefers t over x (WTF not symvar like we do?)


I can think of two "fixes":
1.  We move the comments up to documentation.
2.  We research what Matlab SMT does and try to duplicate it.
Pesumably they fall-back on symvar if they don't find t (?)

My $0.02: relying on this magic stuff is insane for anything remotely serious; Mike's "workaround" is The Right Way.  But I suppose we might as well be insane in the same way as Matlab's SMT.

Colin Macdonald <cbm>
Thu 04 Apr 2019 05:16:19 AM UTC, comment #2: 

I think this may be a valid Matlab compatibility bug. The Matlab docs say that 't' is the default independent variable

https://www.mathworks.com/help/symbolic/laplace.html

I also noticed the 3-argument form, which is another workaround you can use, this does work correctly in Octave


>> laplace (sin (w*t), t, s)
ans = (sym)

     w
  ───────
   2    2
  s  + w


Mike Miller <mtmiller>
Group Member
Thu 04 Apr 2019 04:59:26 AM UTC, comment #1: 

It's nothing special about the variable 'w', but it's about the sorting order of the variables. When you pass an expression instead of a function as the first argument, the 'symvar' function is used to extract the variable that is closest to 'x'. I think this is a Matlab compatibility thing. @cbm is that right?

So for the expressions 'sin(a*t)' and 'sin(b*t), 't' is chosen as the independent variable that the Laplace transform is computed over. But for 'sin(w*t)', 'w' is chosen instead of 't'.

One example way to work around this is to define the expression as a function of t:


>> f(t) = sin(w*t);
>> laplace (f)
ans = (sym)

     w
  ───────
   2    2
  s  + w


Mike Miller <mtmiller>
Group Member
Thu 04 Apr 2019 03:57:48 AM UTC, original submission:  


>> pkg load symbolic
>> syms a b w t
Symbolic pkg v2.7.1: Python communication link active, SymPy v1.3.
>> laplace(sin(a*t))
ans = (sym)

     a
  -------
   2    2
  a  + s

>> laplace(sin(b*t))
ans = (sym)

     b
  -------
   2    2
  b  + s

>> laplace(sin(w*t))
ans = (sym)

     t
  -------
   2    2
  s  + t

The Laplace Transform for symbolic variables a and b give the correct result.  We see that in the code I provide above. However, the Laplace transform of sin(w*t) gives an incorrect value. We see the incorrect result above. Is w a special variable to Octave?  Is Octave getting the wrong variable for integration in the case for w?  It's odd that a and b work correctly but w fails.

Thank you for looking into this.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by cbm (Posted a comment)
  • -email is unavailable- added by mtmiller
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-04-07 mtmiller StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-04-04 mtmiller Severity3 - Normal 2 - Minor
        Item GroupIncorrect Result Matlab Compatibility
        StatusNone Confirmed
    2019-04-04 mtmiller Carbon-Copy- Added cbm
    2019-04-04 mtmiller SummarySymbolic Laplace transform of sin(w*t) gives wrong value [octave forge] (symbolic) Laplace transform of sin(w*t) gives wrong value

    Back to the top

    Powered by Savane 3.13-caa5.
    Corresponding source code