Skip to content

Commit 8be0fec

Browse files
committed
docs:Better examples.
1 parent 0ba1f92 commit 8be0fec

2 files changed

Lines changed: 62 additions & 4 deletions

File tree

README-work.md

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff 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
126128
use CortexJS;
127129
my $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
139143
my $expr = $ce.parse-latex('3x^2 + 2x^2 + x + 5');
140144
say "{$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

README.md

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff 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
126128
use CortexJS;
127129
my $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
145149
my $expr = $ce.parse-latex('3x^2 + 2x^2 + x + 5');
146150
say "{$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

0 commit comments

Comments
 (0)