Math. Js: An Advanced Mathematics Library For JavaScript



Download 477,21 Kb.
Pdf ko'rish
bet3/7
Sana11.08.2022
Hajmi477,21 Kb.
#846896
1   2   3   4   5   6   7
Bog'liq
MCSE.2018.011111122

Description Math.js 
syntax 
JavaScript 
API 
A range from 1 to 5 
1:5 math.range(1, 
6) 
Transpose matrix A 
A' math.transpose(A) 
Get the second col-
umn of rows 1 
through 4 of matrix 

A[1:4, 2] 
math.subset(A, 
math.index(math.range(0, 4), 1)) 
Add two physical 
quantities 
0.5 m + 5 cm 
math.add(math.unit(0.5, 'm'),
math.unit(5, 'cm')) 
Multiply a complex 
number 
2 * (2 + 3i) 
math.multiply(2, math.complex(2, 3)) 
23
January/February 2018
www.computer.org/cise


THE RISE OF JAVASCRIPT 
Create and use an 
object 
obj = {a: 2, b: 
3} 
c = obj.a + 
obj.b 
obj = {a: 2, b: 3} 
c = obj.a + obj.b 
The math.js syntax is much more concise than the native JavaScript API. Math.js also uses one-
based indices rather than zero-based, since the former is more common in mathematics software 
applications. Each math.js operator has an associated function in the native JavaScript API, 
which satisfies the needs of both audiences served by math.js: programmers and mathematicians. 
The math.js syntax is understood by the built-in expression parser. Parsing an expression returns 
an abstract syntax tree
27,28
representing the expression: 
var tree = math.parse('3x ^ 2 + 5'); // abstract syntax tree 
Math.js evaluates this expression by first compiling the tree into native JavaScript code. The 
compiled code can then be evaluated while providing values for any symbols used in the expres-
sion:
var compiled = tree.compile(); 
var result = compiled.eval( {x: 4} ); // 53 
Math.js can also perform algebraic operations by transforming abstract syntax trees: 
var tree = math.parse('x * x^2 '); 
math.simplify(tree); // x ^ 3 
math.derivative(tree); // 3 * x ^ 2 
The math.js syntax and expression parser are demonstrated further in the following case study. 
CASE STUDY: ROCKET TRAJECTORY 
OPTIMIZATION 
In this example, we show how math.js can be extended using a custom function to solve a sys-
tem of ordinary differential equations (ODEs). We will demonstrate this by simulating the ascent 
stage of the Apollo Lunar Module. In solving this problem, we will try to maintain generality so 
that the same methods can be used to solve many different systems of ODEs. For reference, the 
full code of this case study can be found in the examples section of the math.js library.
29
The lunar ascent can be modeled using the following system of ODEs, representing the motion 
of an object in orbit around a planet or moon: 
 
( )
dr
v sin
dt
γ
= ⋅
 
 
( )
2
dv
T
sin
dt
r
m
μ
γ

=

+
 
 
0
sp
dm
T
dt
g I

=
 
 
( )
d
v
cos
dt
r
φ
γ
=
 
 
( )
1
d
v
cos
dt
r
r v
γ
μ
γ


=






 
24
January/February 2018
www.computer.org/cise


COMPUTING IN SCIENCE & ENGINEERING 
The quantities 
r
and 
φ
specify the object’s position in polar coordinates and represent, respec-
tively, the distance from the object to the center of the moon and the angular position of the ob-
ject relative to some reference point. The quantity 

Download 477,21 Kb.

Do'stlaringiz bilan baham:
1   2   3   4   5   6   7




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish