How to upgrade SciPy on Fedora 23

As it was with Fedora 22, the Fedora 23 still ships with SciPy version 0.14.1. To upgrade SciPy please run the following commands as root:

dnf install python-pip
dnf install blas-devel
dnf install lapack-devel
dnf install gcc-c++
dnf groupinstall "Development Tools"

If you now try to upgrade scipy you will get the following error
g++: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory

On Fedora 23 one has also to install rpm-build to avoid errors during compilation of scipy:
dnf search rpm-build

Finally uninstall scipy 0.14.1, download 0.16.0, compile it and install. All with the following command:
pip install --upgrade scipy

scipy.odr.odrpack.odr_error: number of observations do not match

When the length of t does not match the length of observations array,  it may couse this error

t = np.linspace(0.5, 54.5, 18)

P = [29.976, 193.96, 362.64, 454.78, 498.42, 517.14, 515.76, 496.38, 472.14, 432.81, 386.95, 352.93, 318.93, 279.47, 260.19, 230.92, 202.67, 180.3, 159.09, 137.31, 120.47, 104.51, 99.371, 89.606, 75.431, 67.137, 58.561, 55.721]

data = Data(t, P)

When the length of t and P are different, program ends with the error “scipy.odr.odrpack.odr_error: number of observations do not match”

 

Postgresql EESTERROR invalid byte sequence for encoding “UTF8”: 0xff

After Postgres update one of our php web gallery stopped working. Uploading of a photo ended with the following error: invalid byte sequence for encoding "UTF8": 0xff

For years we have allways put an ‘E’ before escaped image data in our INSERT queries.
pg_query("INSERT INTO gallery (name, data) VALUES ('My photo', E'$escaped_image')");

I found the solution in http://php.net/manual/en/function.pg-escape-bytea.php

// Escape image data
$escaped = pg_escape_bytea($data);

// The wrong code, which stopped working after Postgres update
pg_query("INSERT INTO gallery (name, data) VALUES ('Pine trees', E'$escaped')");

// The right code
pg_query("INSERT INTO gallery (name, data) VALUES ('Pine trees', '$escaped')");

Configure LightTable editor so it behaves more like SublimeText

In LightTable press Ctrl-Space to open Commands pane. Type “settings” and choose “Settings: User keymap”.
It will open keymap configuration. The following configuration adds PageUP and PageDown keyboard shortcuts to switch between opened files and Ctrl-/ shortcut to comment/uncomment current line.

;; User keymap
;; -----------------------------
;; Keymaps are stored as a set of diffs that are merged together together
;; to create the final set of keys. You can modify these diffs to either add
;; or subtract bindings.
;;
;; Like behaviors, keys are bound by tag. When objects with those tags are active
;; the key bindings are live. Keys can be bound to any number of Light Table commands,
;; allowing you the flexibility to execute multiple operations together. To see a list
;; of all the commands you can execute, start typing a word related to the thing you
;; want to do in between the square brackets (e.g. type "editor").

{:+ {:app {}

     :editor {"alt-w" [:editor.watch.watch-selection]
              "alt-shift-w" [:editor.watch.unwatch]
              "pmeta-/" [:toggle-comment-selection]}
     :tabs {"pmeta-pageup" [:tabs.prev]
            "pmeta-pagedown" [:tabs.next]
            }
     }}

To add line numbers or change color theme, you need to configure “User behaviors”. Press Ctrl-Space to open Commands pane, type “settings” and choose “Settings: User behaviors”.
Here is my configuration:

;; User behaviors
;; -----------------------------
;; Behaviors are stored as a set of diffs that are merged together
;; to create the final set of functionality that makes up Light Table. You can
;; modify these diffs to either add or subtract functionality.
;;
;; Behaviors are added to tags, objects with those tags then automatically gain
;; whatever logic the behavior imparts. To see a list of user-level behaviors,
;; start typing a word related to the functionality you want in between the square
;; brackets (e.g. "theme").

{:+ {
     ;; The app tag is kind of like global scope. You assign behaviors that affect
     ;; all of Light Table here
     :app [(:lt.objs.style/set-skin "dark")]

     ;; The editor tag is applied to all editors
     :editor [:lt.objs.editor/wrap
              :lt.objs.editor/line-numbers
              (:lt.objs.style/font-settings "" "12" "1.2")
              (:lt.objs.style/set-theme "monokai")]

     ;; Here we can add behaviors to just clojure editors
     :editor.clojure [(:lt.objs.langs.clj/print-length 1000)]}

 ;; You can use the subtract key to remove behavior that may get added by
 ;; another diff
 :- {:app []}}

Mysqli: Unknow server host

PHP can fail to connect to a MySQL database when a custom port number is specified.
In the old-style you would write like this:
$link = mysql_connect("dbhost.info:6603", "dbuser", "dbpaswd",);

Now with mysqli the same approach does not work.
$mysqli = new mysqli("dbhost.info:6603", "dbuser", "dbpaswd", "databasename");
If you try to connect this way using mysqli, it will fail with an error Unknow server host ‘dbhost.info:6603’:

Continue reading Mysqli: Unknow server host

libSBML 5.8.0 in Fedora 19 with Python bindings

How to install libSBML 5.8.0 in Fedora 19 with Python bindings

Install compiler
yum install gcc-c++
yum groupinstall "Development Tools"

Install some additional packages if needed
yum install python-devel
yum install libxml2-devel
yum install swig

Compile and install libSBML
Go to the directory where you have exctracted libsbml source and run these 3 commands
./configure --with-python
make
make install

Make libsbml accessible to Python
In Fedora 18 you would export full path to libsbml:
export PYTHONPATH=/usr/local/lib64/python2.7/site-packages/libsbmlIn Fedora 18 you would import _libsbml not just import libsbml.

In Fedora 19 you have to export path like this:
export PYTHONPATH=/usr/local/lib64/python2.7/site-packages/

The export command expires when user leaves his/her session.

Use the libSBML in your code
import libsbml

[How to] Trajektorijas pagrieziena rādiusa aprēķināšana zinot 3 punktu koordinātes

pagrieziena_radiuss

Punktu A, B, C koordinātes ir zināmas no mērījumiem– tās ir attiecīgi x1, y1, x2, y2, x3, y3. Riņķa līnijas centrs ir punkts O, kura koordinātes x, y nav zināmas. Izmantojot Pitagora teorēmu, varam uzrakstīt 3 vienādojumu sistēmu, kas saista zināmās koordinātes ar x, y un meklējamo rādiusu r:

(x – x1)2 + (y – y1)2 = r2
(x – x2)2 + (y – y2)2 = r2
(x – x3)2 + (y – y3)2 = r2

Vienādojumu sistēmu var risināt, piemēram, no pirmā vienādojuma atņemot otro – iegūsim sakarību y(x), ko tālāk var ievietot trešajā vienādojumā. Tomēr izteiksmes ātri kļūst pārāk garas aprēķiniem “ar roku”. Izmantosim vienu no brīvi pieejamajām datoralgebras programmām – Maxima (versija 5.27.0, http://maxima.sourceforge.net).

Vienādojumu sistēma kā uzdevums programmai Maxima izskatās šādi:

eq_1: (x - x1)^2 + (y - y1)^2 = r^2$
eq_2: (x - x2)^2 + (y - y2)^2 = r^2$
eq_3: (x - x3)^2 + (y - y3)^2 = r^2$
solve ([eq_1, eq_2, eq_3],[x,y,r]);

Rādiusam r programma sniedz risinājumu:

r=(sqrt(y2^2*y3^4-2*y1*y2*y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*x1^2*x2^2*y1*y2+x3^2*y1^4-2*x2*x3*y1^4+x2^2*y1^4+x3^4*y1^2-2*x2*x3^3*y1^2-2*x1*x3^3*y1^2+2*x2^2*x3^2*y1^2+2*x1*x2*x3^2*y1^2+2*x1^2*x3^2*y1^2-2*x2^3*
x3*y1^2+2*x1*x2^2*x3*y1^2-4*x1^2*x2*x3*y1^2+x2^4*y1^2-2*x1*x2^3*y1^2+2*x1^2*x2^2*y1^2+x2^2*x3^4-2*x1*x2*x3^4+x1^2*x3^4-2*x2^3*x3^3+2*x1*x2^2*x3^3+2*x1^2*x2*
x3^3-2*x1^3*x3^3+x2^4*x3^2+2*x1*x2^3*x3^2-6*x1^2*x2^2*x3^2+2*x1^3*x2*x3^2+x1^4*x3^2-2*x1*x2^4*x3+2*x1^2*x2^3*x3+2*x1^3*x2^2*x3-2*x1^4*x2*x3+x1^2*x2^4-2*x1^3
*x2^3+x1^4*x2^2))/((2*x2-2*x1)*y3+(2*x1-2*x3)*y2+(2*x3-2*x2)*y1)

Redzams, ka meklēto rādiusu r var aprēķināt no 6 zināmajiem skaitļiem – koordinātēm x1, y1, x2, y2, x3, y3 – izmantojot tikai vienkāršas aritmētiskās darbības.
Atrisinājumā ir dalīšana ar izteiksmi

(2*x2-2*x1)*y3+(2*x1-2*x3)*y2+(2*x3-2*x2)*y1

Šīs izteiksmes vērtība kļūst vienāda ar 0, ja visi trīs punkti A, B un C atrodas uz vienas taisnes – to var iztēloties kā pagriezienu, kura rādiuss ir bezgalīgi liels.
Varam pārbaudīt izteiksmes pareizību ar vienkāršu piemēru programmā Maxima:

x1: 1;
y1: 0;
x2: 0;
y2: 1;
x3: -1;
y3: 0;

r: (sqrt(y2^2*y3^4-2*y1*y2*y3^4+y1^2*y3^4+x2^2*y3^4-2*x1*x2*y3^4+x1^2*
y3^4-2*y2^3*y3^3+2*y1*y2^2*y3^3+2*y1^2*y2*y3^3-2*x2^2*y2*y3^3+4*x1*x2*y2*y3^3-2*x1^2*y2*y3^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^2*y1^2-2*x2^3*
x3*y1^2+2*x1*x2^2*x3*y1^2-4*x1^2*x2*x3*y1^2+x2^4*y1^2-2*x1*x2^3*y1^2+2*x1^2*x2^2*y1^2+x2^2*x3^4-2*x1*x2*x3^4+x1^2*x3^4-2*x2^3*x3^3+2*x1*x2^2*x3^3+2*x1^2*x2*
x3^3-2*x1^3*x3^3+x2^4*x3^2+2*x1*x2^3*x3^2-6*x1^2*x2^2*x3^2+2*x1^3*x2*x3^2+x1^4*x3^2-2*x1*x2^4*x3+2*x1^2*x2^3*x3+2*x1^3*x2^2*x3-2*x1^4*x2*x3+x1^2*x2^4-2*x1^3
*x2^3+x1^4*x2^2))/((2*x2-2*x1)*y3+(2*x1-2*x3)*y2+(2*x3-2*x2)*y1);

1
0
0
1
-1
0
1.0 <---- aprēķinātais rādiuss ir pareizs.

Mēģinājumi vienkāršot atrisinājumu, savelkot līdzīgos locekļus vai iznesot pirms iekavām kopējos reizinātājus, nedod būtiskus rezultātus. Apjomīgā izteiksme varētu būt pārsteigums – kāpēc tik vienkāršam uzdevumam ir tik sarežģīts atrisinājums. Domāju, ka izskaidrojums varētu būt tajā, ka katrs no 6 skaitļiem (koordinātēm) ietekmē rezultātu (rādiusu) sarežģītā mijiedarbībā ar katru no pārējiem 5 skaitļiem, tādēļ arī izteiksmē tik daudz locekļu, kur katra koordināte reizināta pati ar sevi un citām koordinātēm dažādās pakāpēs.

Mg.phys. Andris Mednis