File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -122,24 +122,45 @@ flowchart TD
122122
123123## Basic usage
124124
125+ Make a new computation engine object and evaluate a LaTeX expression:
126+
125127``` raku
126128use CortexJS;
127129my $ ce = ComputeEngine. new ;
128130
129131$ ce . evaluate($ ce . parse-latex(' e^{i\\ pi}' ))
130132```
131133
134+ Expand expression:
135+
132136``` raku
133137$ ce . to-latex($ ce . expand($ ce . parse-latex(' (a + b)^2' )));
134138```
135139
136- ``` raku
137- LEAVE $ ce . close ;
140+ Simplify expression:
138141
142+ ``` raku
139143my $ expr = $ ce . parse-latex(' 3x^2 + 2x^2 + x + 5' );
140144say " { $ ce . to-latex($ expr )} = { $ ce . to-latex($ ce . simplify($ expr ))} " ;
141145```
142146
147+ Using assignment for repeated expression evaluation:
148+
149+ ``` raku
150+ my $ expr = $ ce . parse-latex(" 3x^2+4x+2" );
151+
152+ for (0 , 0.1 ... 1 ) -> $ x {
153+ $ ce . assign(' x' , $ x );
154+ say " f($ x ) = { $ ce . evaluate($ expr )} " ;
155+ }
156+ ```
157+
158+ Can be put in the last code block:
159+
160+ ``` raku
161+ LEAVE $ ce . close ;
162+ ```
163+
143164----
144165
145166## References
Original file line number Diff line number Diff line change @@ -122,6 +122,8 @@ flowchart TD
122122
123123## Basic usage
124124
125+ Make a new computation engine object and evaluate a LaTeX expression:
126+
125127``` raku
126128use CortexJS;
127129my $ ce = ComputeEngine. new ;
@@ -132,23 +134,58 @@ $ce.evaluate($ce.parse-latex('e^{i\\pi}'))
132134# -1
133135```
134136
137+ Expand expression:
138+
135139``` raku
136140$ ce . to-latex($ ce . expand($ ce . parse-latex(' (a + b)^2' )));
137141```
138142```
139143# a^2+b^2+2ab
140144```
141145
142- ``` raku
143- LEAVE $ ce . close ;
146+ Simplify expression:
144147
148+ ``` raku
145149my $ expr = $ ce . parse-latex(' 3x^2 + 2x^2 + x + 5' );
146150say " { $ ce . to-latex($ expr )} = { $ ce . to-latex($ ce . simplify($ expr ))} " ;
147151```
148152```
149153# 2x^2+3x^2+x+5 = 5x^2+x+5
150154```
151155
156+ Using assignment for repeated expression evaluation:
157+
158+ ``` raku
159+ my $ expr = $ ce . parse-latex(" 3x^2+4x+2" );
160+
161+ for (0 , 0.1 ... 1 ) -> $ x {
162+ $ ce . assign(' x' , $ x );
163+ say " f($ x ) = { $ ce . evaluate($ expr )} " ;
164+ }
165+ ```
166+ ```
167+ # f(0) = 2
168+ # f(0.1) = 2.43
169+ # f(0.2) = 2.92
170+ # f(0.3) = 3.47
171+ # f(0.4) = 4.08
172+ # f(0.5) = 4.75
173+ # f(0.6) = 5.48
174+ # f(0.7) = 6.27
175+ # f(0.8) = 7.12
176+ # f(0.9) = 8.03
177+ # f(1) = 9
178+ ```
179+
180+ Can be put in the last code block:
181+
182+ ``` raku
183+ LEAVE $ ce . close ;
184+ ```
185+ ```
186+ # (Any)
187+ ```
188+
152189----
153190
154191## References
You can’t perform that action at this time.
0 commit comments