Code Monkey home page Code Monkey logo

Comments (11)

blink1073 avatar blink1073 commented on July 1, 2024

Matthias,

I'm glad oct2py has proven useful to you. Have you tried running similar code directly in octave? I will try it both ways and let you know what I get. Yes, the tracebacks should be clearer as to where the error source is. I'll take that as a bug of its own.

Regards,

Steve Silvester

On Sep 27, 2012, at 8:23 AM, MatthiasKauer [email protected] wrote:

Hi,
I'm trying to use octave's c2d function to transfer a continuous time control system to a discrete one.
This seems to work fine as long as A, B are the same size. The code below however (where B is 2x1) fails however informing me that the numbers of columns must match (in the temporary .mat file, I assume)

I'm using scipy 0.9.0, python 2.7 (both installed from the ubuntu repos) and oct2py-0.3.5-py2.7.egg that I installed via easy-install (and that was working fine for solving the discrete algebraic Riccati equation - helped me out big time!)

Code:
from oct2py import Oct2Py
oc = Oct2Py()
import scipy as sp

A = sp.array([[1.0, 1.0],[0,1.0]])
B = sp.array([ [1.0], [0.0] ])
C =sp.eye(2)

sys = oc.ss(A,B,C,[])
print sys
dsys = oc.call('c2d', sys,0.5)
print dsys

OUTPUT:
{'a': array([[ 1., 1.],
[ 0., 1.]]), 'c': array([[ 1., 0.],
[ 0., 1.]]), 'b': array([[ 1.],
[ 0.]]), 'd': array([[ 0.],
[ 0.]]), 'stname': [u'x1', u'x_2'], 'tsam': 0.0, 'n': 2.0, 'sys': array([[ 2., 0., 0., 1.]]), 'nz': 0.0, 'outname': [u'y_1', u'y_2'], 'yd': array([[ 0., 0.]]), 'inname': u'u_1'}
Traceback (most recent call last):
File "/media/sf_Dropbox/Work_2012_07+/ConVerIterate/Python/oct2py_experiment/oct2py_c2d.py", line 21, in
dsys = oc.call('c2d', sys,0.5)
File "/usr/local/lib/python2.7/dist-packages/oct2py-0.3.5-py2.7.egg/oct2py/_oct2py.py", line 211, in call
resp = self._eval(cmd, verbose=verbose)
File "/usr/local/lib/python2.7/dist-packages/oct2py-0.3.5-py2.7.egg/oct2py/_oct2py.py", line 360, in _eval
raise Oct2PyError(msg)
oct2py.utils.Oct2PyError: """
load /tmp/tmpuBWU8L.mat "A" "B"
[a] = c2d(A, B)
save "-v6" /tmp/tmpHwjPoP.mat "a
"
"""
number of columns must match (5 != 3)


Reply to this email directly or view it on GitHub.

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Matthias,

I fixed the bug in the latest repository. Cheers.

from oct2py.

MatthiasKauer avatar MatthiasKauer commented on July 1, 2024

Hi Steve,
I'm impressed that you could fix this so quickly.

Just to confirm: I can not get this fix via easy-install yet, can I? git clone -> setup.py or something similar is required, right?

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Correct, but I'll try to release 0.3.6 this weekend.

Regards,

Steve Silvester

On Oct 5, 2012, at 11:22 PM, MatthiasKauer [email protected] wrote:

Hi Steve,
I'm impressed that you could fix this so quickly.

Just to confirm: I can not get this fix via easy-install yet, can I? git clone -> setup.py or something similar is required, right?


Reply to this email directly or view it on GitHub.

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Sorry for the confusion if you had tried to use the git master repo, I had made the change in the 0.3.4 branch instead of the main. All changes have been merged to main, and I released 0.3.6, which should address your issue.

Cheers.

from oct2py.

MatthiasKauer avatar MatthiasKauer commented on July 1, 2024

hi, I just tried running easy_install oct2py and it told me that
"oct2py 0.3.5 is already the active version in easy-install.pth"

Am I doing something wrong? [Ubuntu 12.04, Python 2.7]

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Does this work?
easy_install --upgrade oct2py

Regards,

Steve Silvester

On Oct 15, 2012, at 6:59 PM, MatthiasKauer [email protected] wrote:

hi, I just tried running easy_install oct2py and it told me that
"oct2py 0.3.5 is already the active version in easy-install.pth"

Am I doing something wrong?


Reply to this email directly or view it on GitHub.

from oct2py.

MatthiasKauer avatar MatthiasKauer commented on July 1, 2024

I think the install worked now.
Bug is still the same however. Did you only change the error messages?

Should I start examining the temporary .mat files?

Traceback (most recent call last):
File "/media/sf_Forge/Work_2012_07+/ConVerIterate/Python/oct2py_experiment/oct2py_c2d.py", line 21, in
dsys = oc.call('c2d', sys,0.5)
File "/usr/local/lib/python2.7/dist-packages/oct2py-0.3.6-py2.7.egg/oct2py/oct2py.py", line 206, in call
resp = self.eval(cmd, verbose=verbose)
File "/usr/local/lib/python2.7/dist-packages/oct2py-0.3.6-py2.7.egg/oct2py/oct2py.py", line 355, in eval
raise Oct2PyError(msg)
oct2py.utils.Oct2PyError: Tried to run:
"""
load /tmp/tmpMSS6TN.mat "A
" "B
"
[a
_] = c2d(A__, B__)
save "-v6" /tmp/tmpCYcTKT.mat "a__"
"""
Octave returned:
number of columns must match (5 != 3)

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Matthias, can you make the change below to your /usr/local/lib/python2.7/dist-packages/oct2py-0.3.6-py2.7.egg/oct2py/_matread.py and let me know if that fixes it? I made this change when addressing your bug, and then accidentally reverted it prior to release

diff --git a/oct2py/_matread.py b/oct2py/_matread.py
index dd28991..d30fd97 100644
--- a/oct2py/_matread.py
+++ b/oct2py/_matread.py
@@ -94,7 +94,7 @@ class MatRead(object):
                 if "'|O" in str(val.dtype):
                     val = self._get_data(val)
                 if val.size == 1:
-                    val = val.flatten()[0]
+                    val = val.flatten()
         if val.dtype == np.object:
             if len(val.shape) > 2:
                 val = val.T

from oct2py.

MatthiasKauer avatar MatthiasKauer commented on July 1, 2024

that was one small change with a huge effect. Seems to be working now.
I'll report back if I find other errors.

Thank you so much again :+1

{'a': array([[ 1., 1.],
[ 0., 1.]]), 'c': array([[ 1., 0.],
[ 0., 1.]]), 'b': array([[ 1.],
[ 0.]]), 'd': array([[ 0.],
[ 0.]]), 'stname': [u'x_1', u'x_2'], 'tsam': 0.0, 'n': 2.0, 'sys': array([[ 2., 0., 0., 1.]]), 'nz': 0.0, 'outname': [u'y_1', u'y_2'], 'yd': array([[ 0., 0.]]), 'inname': [u'u_1']}
{'a': array([[ 1.64872127, 0.82436064],
[ 0. , 1.64872127]]), 'c': array([[ 1., 0.],
[ 0., 1.]]), 'b': array([[ 0.64872127],
[ 0. ]]), 'd': array([[ 0.],
[ 0.]]), 'stname': [u'x_1_d', u'x_2_d'], 'tsam': 0.5, 'n': 0.0, 'sys': array([[ 2., 0., 0., 1.]]), 'nz': 2.0, 'outname': [u'y_1', u'y_2'], 'yd': array([[ 1., 1.]]), 'inname': [u'u_1']}
{'a': array([[ 1.64872127, 0.82436064],
[ 0. , 1.64872127]]), 'c': array([[ 1., 0.],
[ 0., 1.]]), 'b': array([[ 0.64872127],
[ 0. ]]), 'd': array([[ 0.],
[ 0.]]), 'stname': [u'x_1_d', u'x_2_d'], 'tsam': 0.5, 'n': 0.0, 'sys': array([[ 2., 0., 0., 1.]]), 'nz': 2.0, 'outname': [u'y_1', u'y_2'], 'yd': array([[ 1., 1.]]), 'inname': [u'u_1']}

from oct2py.

blink1073 avatar blink1073 commented on July 1, 2024

Thanks again @MatthiasKauer, this will be in oct2py 0.4.0, forthcoming this weekend.

from oct2py.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.