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

 
 

bug #57726: [octave forge] (symbolic) dsolve should return expression instead of equation

Submitted by:  Jing-Chen Peng <jcpeng>
Submitted on:  Sun 02 Feb 2020 03:49:13 PM UTC  
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Confirmed Assigned to:  None
Originator Name:  jcpeng Open/Closed:  Open
Release:  dev Operating System:  Any

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Mon 03 Feb 2020 11:29:53 PM UTC, comment #9: 

Thanks! I'll look into it there.

Jing-Chen Peng <jcpeng>
Mon 03 Feb 2020 11:26:48 PM UTC, comment #8: 

If you are comfortable with GitHub, you can also report the details as an issue here: https://github.com/cbm755/octsympy/issues. And if you're interested in helping to fix this, I'm sure a patch or a PR would be very welcome.

Mike Miller <mtmiller>
Project Administrator
Mon 03 Feb 2020 10:48:46 PM UTC, comment #7: 

Yes, that looks correct.

Thanks!

Jing-Chen Peng <jcpeng>
Mon 03 Feb 2020 10:42:07 PM UTC, comment #6: 

Ok, I verified that the complete example does run in Matlab, thank you. If you look closer, you can see that the main difference is the return value of 'dsolve'. In Matlab, 'dsolve' returns an expression, but Octave 'dsolve' returns an equality.

If you run 'rhs' on the return value of Octave 'dsolve', you get the same answer as Matlab.

So the compatibility bug here is that 'dsolve' should not return an equality like "y(t) == expr", it should just return "expr". Does that look right to you?

Reopening and changing the summary.

Mike Miller <mtmiller>
Project Administrator
Mon 03 Feb 2020 10:27:23 PM UTC, comment #5: 

The following code runs just fine in matlab:

clear all
clc
syms y(t)
dy = diff(y)
deq = diff(y, 2) + dy + y == 0
soln = dsolve(deq, y(0) == 1, dy(0) ==  0)
y_eval = double(vpa(subs(soln, t, 4)))

Sorry for the messy post / double post, first time on the forums and having a bit of trouble getting around haha

Jing-Chen Peng <jcpeng>
Mon 03 Feb 2020 10:13:59 PM UTC, comment #4: 

Ok, this also doesn't work in Matlab. As far as I can tell this type of expression is not meant to work, conversion from an equality to a double constant does not automatically extract the right-hand side of the equation. Do you have evidence or examples that work in Matlab that show it should work?

In the future, please paste a plain text example instead of a screenshot, so that another user like me can copy and paste the text instead of having to retype from the screenshot.

I don't think this change is appropriate since it is already quite simple for the user to get the double value by using the 'rhs' function. Closing as won't fix.

Mike Miller <mtmiller>
Project Administrator
Mon 03 Feb 2020 08:58:23 AM UTC, comment #3: 

comment #2:

>
> comment #1:
> > Thank you for your bug report. Can you please complete it by giving a small self contained example that demonstrates the original error with 'vpa' and 'double' that you found?
>
>

Jing-Chen Peng <jcpeng>
Mon 03 Feb 2020 08:56:09 AM UTC, comment #2: 

comment #1:

> Thank you for your bug report. Can you please complete it by giving a small self contained example that demonstrates the original error with 'vpa' and 'double' that you found?


Jing-Chen Peng <jcpeng>
Mon 03 Feb 2020 08:26:59 AM UTC, comment #1: 

Thank you for your bug report. Can you please complete it by giving a small self contained example that demonstrates the original error with 'vpa' and 'double' that you found?

Mike Miller <mtmiller>
Project Administrator
Sun 02 Feb 2020 03:49:13 PM UTC, original submission:  

I was messing around with the symbolic package and wanted to evaluate a symbolic expression with subs(), vpa(), and double(), but vpa() in octave returns an equality object which can't be converted to a complex or floating point number directly in python.

The new python code for double():
  cmd = { '(x,) = _ins'
          'if x == zoo:'  % zoo -> Inf + Infi
          '    return (float(sp.oo), float(sp.oo))'
          'if x == nan:'
          '    return (float(nan), 0.0)'
          % Adding check for Eq type to evaluate vpa()'d symbolic
          %     variables.
          'if isinstance(x, Eq):'
          '    x = complex(x.rhs)'
          '    return (x.real, x.imag)'
          'x = complex(x)'
          'return (x.real, x.imag)'
        };

Jing-Chen Peng <jcpeng>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #48342:  matlab.m added by jcpeng (155B - application/octet-stream - The following code works in matlab.)
file #48336:  octave.png added by jcpeng (16KiB - image/png - Hi, I've attached an image that sums up everything. I created a differential equation with the symbolic package and solved it, but when I tried to extract the result as a double precision value it would fail because even the vpa())

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by jcpeng (Submitted the item)
  • -email is unavailable- added by jcpeng
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 14 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-03 mtmiller Item GroupOther => Matlab Compatibility
        StatusWont Fix => Confirmed
        Open/ClosedClosed => Open
        Release5.1.0 => dev
        Operating SystemMicrosoft Windows => Any
        Summary[octave forge] (symbolic) double not working on symbolic expressions => [octave forge] (symbolic) dsolve should return expression instead of equation
    2020-02-03 jcpeng Attached File- => Added matlab.m, #48342
    2020-02-03 mtmiller StatusNeed Info => Wont Fix
        Open/ClosedOpen => Closed
    2020-02-03 jcpeng Attached File- => Added octave.png, #48336
    2020-02-03 mtmiller CategoryOctave Function => Octave Forge Package
        StatusNone => Need Info
        Summarydouble() not working on the symbolic expressions => [octave forge] (symbolic) double not working on symbolic expressions
    2020-02-02 jcpeng Carbon-Copy- => Added jcpeng24@gmail.com

    Back to the top


    Powered by Savane 3.5