AppleScript名:MatRによる行列計算テスト v1 |
— Created 2017-05-15 by Takaaki Naganoya — 2017 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "DCMatrix" –https://github.com/davidcox95/MatR –指定数値、指定サイズ(行、列)で行列データを作成する set aMatrix to current application’s |Matrix|’s alloc()’s initWithValue:(current application’s NSNumber’s numberWithDouble:5) andRows:3 byColumns:4 (aMatrix’s |print|()) (* 5 5 5 5 5 5 5 5 5 5 5 5 *) –行列データに数値を加算する set bMatrix to current application’s |Matrix|’s alloc()’s initWithValue:(current application’s NSNumber’s numberWithDouble:7) andRows:4 byColumns:3 set bScalar to current application’s NSNumber’s numberWithDouble:2 set bRes to bMatrix’s addScalar:bScalar bRes’s |print|() (* 9 9 9 9 9 9 9 9 9 9 9 9 *) –行列データから数値を減算する set cScalar to current application’s NSNumber’s numberWithDouble:3 set cRes to bMatrix’s subtractScalar:cScalar cRes’s |print|() (* 4 4 4 4 4 4 4 4 4 4 4 4 *) –行列データに数値を乗算する set dScalar to current application’s NSNumber’s numberWithDouble:2 set eRes to bMatrix’s multiplyScalar:dScalar eRes’s |print|() (* 14 14 14 14 14 14 14 14 14 14 14 14 *) –行列データに数値を除算する set fScalar to current application’s NSNumber’s numberWithDouble:2 set fRes to bMatrix’s divideScalar:fScalar fRes’s |print|() (* 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 3.5 *) –行列同士の加算 set m4 to current application’s |Matrix|’s alloc()’s initWithValue:(current application’s NSNumber’s numberWithDouble:4) andRows:3 byColumns:3 set m2 to current application’s |Matrix|’s alloc()’s initWithValue:(current application’s NSNumber’s numberWithDouble:2) andRows:3 byColumns:3 set gRes to m4’s addMatrix:m2 gRes’s |print|() (* 6 6 6 6 6 6 6 6 6 *) –行列同士の減算 set hRes to m4’s subtractMatrix:m2 hRes’s |print|() (* 2 2 2 2 2 2 2 2 2 *) –行列同士の乗算 set iRes to m4’s multiplyMatrix:m2 iRes’s |print|() (* 24 24 24 24 24 24 24 24 24 *) |
More from my site
(Visited 35 times, 1 visits today)