-
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
poly: add examples for eval and basic operations
- Loading branch information
1 parent
e736526
commit 6e57a00
Showing
4 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Example - poly_eval 📘 | ||
|
||
This example demonstrates the usage of the V Scientific Library for evaluating polynomial at given | ||
value of x. | ||
|
||
## Instructions | ||
|
||
1. Ensure you have the V compiler installed. You can download it from [here](https://vlang.io). | ||
2. Ensure you have the VSL installed. You can do it following the [installation guide](https://github.com/vlang/vsl?tab=readme-ov-file#-installation)! | ||
3. Navigate to this directory. | ||
4. Run the example using the following command: | ||
|
||
```sh | ||
v run main.v | ||
``` | ||
|
||
Enjoy exploring the capabilities of the V Scientific Library! 😊 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module main | ||
|
||
import vsl.poly | ||
|
||
fn main() { | ||
// represent the polynomial 2 * x^2 + 5 * x + 4 | ||
// with x = 4, result is 2 * 4^2 + 5 * 4 + 4 = 56 | ||
coef := [4.0, 5, 2] | ||
result := poly.eval(coef, 4) | ||
println('Evalutated value: ${result}') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Example - poly_eval 📘 | ||
|
||
This example demonstrates the usage of the V Scientific Library for additioning, substracting and | ||
multiplying polynomials. | ||
|
||
## Instructions | ||
|
||
1. Ensure you have the V compiler installed. You can download it from [here](https://vlang.io). | ||
2. Ensure you have the VSL installed. You can do it following the [installation guide](https://github.com/vlang/vsl?tab=readme-ov-file#-installation)! | ||
3. Navigate to this directory. | ||
4. Run the example using the following command: | ||
|
||
```sh | ||
v run main.v | ||
``` | ||
|
||
Enjoy exploring the capabilities of the V Scientific Library! 😊 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
module main | ||
|
||
import vsl.poly | ||
|
||
fn main() { | ||
// Addition | ||
// Degree is not modified unless highest coefficients cancel each other out | ||
poly_1 := [1.0, 12, 3] | ||
poly_2 := [3.0, 2, 7] | ||
result_add := poly.add(poly_1, poly_2) | ||
println('Addition result: ${result_add}') | ||
|
||
// Substraction | ||
// Degree is not modified unless highest coefficients cancel each other out | ||
result_sub := poly.substract(poly_1, poly_2) | ||
println('Substraction result: ${result_sub}') | ||
|
||
// Multiplication | ||
// with given degree n and m for poly_1 and poly_2 | ||
// resulting polynomial will be of degree n + m | ||
result_mult := poly.multiply(poly_1, poly_2) | ||
println('Multplication result: ${result_mult}') | ||
} |