From 36e7c6c546c02844c3974c443b4c4722ba9fb73f Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sat, 27 Jul 2024 20:11:46 +0300 Subject: [PATCH 01/15] Add partial derivatives and tests --- deriv/deriv.v | 31 +++++++++ deriv/deriv_test.v | 166 ++++++++++++++++++++++++++------------------- 2 files changed, 127 insertions(+), 70 deletions(-) diff --git a/deriv/deriv.v b/deriv/deriv.v index 47a2b33cd..b0f352dbf 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -113,3 +113,34 @@ pub fn forward(f func.Fn, x f64, h f64) (f64, f64) { pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { return forward(f, x, -h) } + +pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { + /** + * Computes the partial derivative of a multivariable function with respect to a specified variable. + * + * @param f The multivariable function for which the partial derivative is to be computed. + * @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. + * @param variable The index of the variable with respect to which the partial derivative is to be computed. + * @param h The step size to be used in the central difference method. + * + * @return A tuple containing the value of the partial derivative and the estimated error. + */ + + if variable < 0 || variable >= x.len { + panic('Invalid variable index') + } + + // Define a helper function that converts the multivariate function + // to a univariate function for the specified variable + partial_helper := func.Fn{ + f: fn [f, x, variable] (t f64, _ []f64) f64 { + mut x_new := x.clone() + x_new[variable] = t + return f(x_new) + } + } + + // Use the central difference method to compute the partial derivative + return central(partial_helper, x[variable], h) +} + diff --git a/deriv/deriv_test.v b/deriv/deriv_test.v index f25a5573f..b83d458e1 100644 --- a/deriv/deriv_test.v +++ b/deriv/deriv_test.v @@ -5,116 +5,142 @@ import vsl.float.float64 import math fn f1(x f64, _ []f64) f64 { - return math.exp(x) + return math.exp(x) } fn df1(x f64, _ []f64) f64 { - return math.exp(x) + return math.exp(x) } fn f2(x f64, _ []f64) f64 { - if x >= 0.0 { - return x * math.sqrt(x) - } else { - return 0.0 - } + if x >= 0.0 { + return x * math.sqrt(x) + } else { + return 0.0 + } } fn df2(x f64, _ []f64) f64 { - if x >= 0.0 { - return 1.50 * math.sqrt(x) - } else { - return 0.0 - } + if x >= 0.0 { + return 1.50 * math.sqrt(x) + } else { + return 0.0 + } } fn f3(x f64, _ []f64) f64 { - if x != 0.0 { - return math.sin(1.0 / x) - } else { - return 0.0 - } + if x != 0.0 { + return math.sin(1.0 / x) + } else { + return 0.0 + } } fn df3(x f64, _ []f64) f64 { - if x != 0.0 { - return -math.cos(1.0 / x) / (x * x) - } else { - return 0.0 - } + if x != 0.0 { + return -math.cos(1.0 / x) / (x * x) + } else { + return 0.0 + } } fn f4(x f64, _ []f64) f64 { - return math.exp(-x * x) + return math.exp(-x * x) } fn df4(x f64, _ []f64) f64 { - return -2.0 * x * math.exp(-x * x) + return -2.0 * x * math.exp(-x * x) } fn f5(x f64, _ []f64) f64 { - return x * x + return x * x } fn df5(x f64, _ []f64) f64 { - return 2.0 * x + return 2.0 * x } fn f6(x f64, _ []f64) f64 { - return 1.0 / x + return 1.0 / x } fn df6(x f64, _ []f64) f64 { - return -1.0 / (x * x) + return -1.0 / (x * x) +} + +// Newly added multivariable function and its partial derivatives +fn f_multi(x []f64) f64 { + return x[0]*x[0] + x[1]*x[1] // f(x,y) = x^2 + y^2 +} + +fn df_multi_dx(x []f64) f64 { + return 2*x[0] // ∂f/∂x = 2x +} + +fn df_multi_dy(x []f64) f64 { + return 2*x[1] // ∂f/∂y = 2y } fn test_deriv() { - f1_ := func.Fn.new(f: f1) - df1_ := func.Fn.new(f: df1) - f2_ := func.Fn.new(f: f2) - df2_ := func.Fn.new(f: df2) - f3_ := func.Fn.new(f: f3) - df3_ := func.Fn.new(f: df3) - f4_ := func.Fn.new(f: f4) - df4_ := func.Fn.new(f: df4) - f5_ := func.Fn.new(f: f5) - df5_ := func.Fn.new(f: df5) - f6_ := func.Fn.new(f: f6) - df6_ := func.Fn.new(f: df6) - - assert deriv_test('central', f1_, df1_, 1.0) - assert deriv_test('forward', f1_, df1_, 1.0) - assert deriv_test('backward', f1_, df1_, 1.0) - assert deriv_test('central', f2_, df2_, 0.1) - assert deriv_test('forward', f2_, df2_, 0.1) - assert deriv_test('backward', f2_, df2_, 0.1) - assert deriv_test('central', f3_, df3_, 0.45) - assert deriv_test('forward', f3_, df3_, 0.45) - assert deriv_test('backward', f3_, df3_, 0.45) - assert deriv_test('central', f4_, df4_, 0.5) - assert deriv_test('forward', f4_, df4_, 0.5) - assert deriv_test('backward', f4_, df4_, 0.5) - assert deriv_test('central', f5_, df5_, 0.0) - assert deriv_test('forward', f5_, df5_, 0.0) - assert deriv_test('backward', f5_, df5_, 0.0) - assert deriv_test('central', f6_, df6_, 10.0) - assert deriv_test('forward', f6_, df6_, 10.0) - assert deriv_test('backward', f6_, df6_, 10.0) + f1_ := func.Fn.new(f: f1) + df1_ := func.Fn.new(f: df1) + f2_ := func.Fn.new(f: f2) + df2_ := func.Fn.new(f: df2) + f3_ := func.Fn.new(f: f3) + df3_ := func.Fn.new(f: df3) + f4_ := func.Fn.new(f: f4) + df4_ := func.Fn.new(f: df4) + f5_ := func.Fn.new(f: f5) + df5_ := func.Fn.new(f: df5) + f6_ := func.Fn.new(f: f6) + df6_ := func.Fn.new(f: df6) + + assert deriv_test('central', f1_, df1_, 1.0) + assert deriv_test('forward', f1_, df1_, 1.0) + assert deriv_test('backward', f1_, df1_, 1.0) + assert deriv_test('central', f2_, df2_, 0.1) + assert deriv_test('forward', f2_, df2_, 0.1) + assert deriv_test('backward', f2_, df2_, 0.1) + assert deriv_test('central', f3_, df3_, 0.45) + assert deriv_test('forward', f3_, df3_, 0.45) + assert deriv_test('backward', f3_, df3_, 0.45) + assert deriv_test('central', f4_, df4_, 0.5) + assert deriv_test('forward', f4_, df4_, 0.5) + assert deriv_test('backward', f4_, df4_, 0.5) + assert deriv_test('central', f5_, df5_, 0.0) + assert deriv_test('forward', f5_, df5_, 0.0) + assert deriv_test('backward', f5_, df5_, 0.0) + assert deriv_test('central', f6_, df6_, 10.0) + assert deriv_test('forward', f6_, df6_, 10.0) + assert deriv_test('backward', f6_, df6_, 10.0) + + // Partial derivative test + x := [2.0, 3.0] + h := 1e-5 + + // Partial derivative with respect to x + dx, _ := partial(f_multi, x, 0, h) + assert float64.tolerance(dx, df_multi_dx(x), 1e-5) + + // Partial derivative with respect to y + dy, _ := partial(f_multi, x, 1, h) + assert float64.tolerance(dy, df_multi_dy(x), 1e-5) } fn deriv_test(deriv_method string, f func.Fn, df func.Fn, x f64) bool { - return deriv_near_test(deriv_method, f, df, x, 1e-5) + return deriv_near_test(deriv_method, f, df, x, 1e-5) } fn deriv_near_test(deriv_method string, f func.Fn, df func.Fn, x f64, tolerance f64) bool { - expected := df.eval(x) - h := 1e-5 - result, _ := if deriv_method == 'backward' { - backward(f, x, h) - } else if deriv_method == 'forward' { - forward(f, x, h) - } else { - central(f, x, h) - } - return float64.tolerance(result, expected, tolerance) + expected := df.eval(x) + h := 1e-5 + result, _ := if deriv_method == 'backward' { + backward(f, x, h) + } else if deriv_method == 'forward' { + forward(f, x, h) + } else { + central(f, x, h) + } + return float64.tolerance(result, expected, tolerance) } + From da6d79ef5db508aad8e9d5669b59dd1cad0d8fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:34:31 +0300 Subject: [PATCH 02/15] Update README.md --- deriv/README.md | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/deriv/README.md b/deriv/README.md index 096613e8d..659f3a995 100644 --- a/deriv/README.md +++ b/deriv/README.md @@ -1,3 +1,11 @@ +It seems like I can’t do more advanced data analysis right now. Please try again later. + +However, you can create the `README.md` file on your local machine using the content provided. Here’s how you can do it: + +1. Open a text editor of your choice. +2. Copy and paste the following content into the editor: + +```markdown # 🚀 Numerical Differentiation This module provides functions for computing numerical derivatives of functions. 🧮 @@ -63,9 +71,26 @@ for values greater than `x`. 📉 This function is equivalent to calling `deriv.forward` with a negative step-size. +### `partial` + +```v ignore +pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) +``` + +This function computes the partial derivative of a multivariable function `f` with respect to a specified variable at the point `x` using the central difference method with a step-size of `h`. The partial derivative is returned in `result` and an estimate of its absolute error is returned in `abserr`. + +The function `f` should take an array of coordinates as input and return a single value. The `variable` parameter specifies the index of the variable with respect to which the partial derivative is to be computed. + +The initial value of `h` is used to estimate an optimal step-size, based on the scaling of the truncation error and round-off error in the derivative calculation. The partial derivative is computed by converting the multivariable function into a univariate function for the specified variable and then applying the central difference method. + ## References and Further Reading This work is a spiritual descendent of the Differentiation module in [GSL](https://github.com/ampl/gsl). 📖 Feel free to explore and utilize these numerical differentiation functions in your projects! 🤖📊🔬 +``` + +3. Save the file with the name `README.md`. + +Bu şekilde, `README.md` dosyanız hazır olacaktır. Başka bir yardıma ihtiyacınız olursa lütfen bildirin! From 54fc2e69f2eb383168b094e99c0ca7f94df526ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 20:37:50 +0300 Subject: [PATCH 03/15] Update README for deriv module --- deriv/README.md | 8 -------- 1 file changed, 8 deletions(-) diff --git a/deriv/README.md b/deriv/README.md index 659f3a995..77ded8c80 100644 --- a/deriv/README.md +++ b/deriv/README.md @@ -1,11 +1,3 @@ -It seems like I can’t do more advanced data analysis right now. Please try again later. - -However, you can create the `README.md` file on your local machine using the content provided. Here’s how you can do it: - -1. Open a text editor of your choice. -2. Copy and paste the following content into the editor: - -```markdown # 🚀 Numerical Differentiation This module provides functions for computing numerical derivatives of functions. 🧮 From 6f94cb3a3e3892904d4aec6fbd4498b48eba1c4c Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sat, 27 Jul 2024 23:04:02 +0300 Subject: [PATCH 04/15] Reformat deriv_test.v --- deriv/deriv_test.v | 171 ++++++++++++++++++++++----------------------- 1 file changed, 85 insertions(+), 86 deletions(-) diff --git a/deriv/deriv_test.v b/deriv/deriv_test.v index b83d458e1..4374f1244 100644 --- a/deriv/deriv_test.v +++ b/deriv/deriv_test.v @@ -5,142 +5,141 @@ import vsl.float.float64 import math fn f1(x f64, _ []f64) f64 { - return math.exp(x) + return math.exp(x) } fn df1(x f64, _ []f64) f64 { - return math.exp(x) + return math.exp(x) } fn f2(x f64, _ []f64) f64 { - if x >= 0.0 { - return x * math.sqrt(x) - } else { - return 0.0 - } + if x >= 0.0 { + return x * math.sqrt(x) + } else { + return 0.0 + } } fn df2(x f64, _ []f64) f64 { - if x >= 0.0 { - return 1.50 * math.sqrt(x) - } else { - return 0.0 - } + if x >= 0.0 { + return 1.50 * math.sqrt(x) + } else { + return 0.0 + } } fn f3(x f64, _ []f64) f64 { - if x != 0.0 { - return math.sin(1.0 / x) - } else { - return 0.0 - } + if x != 0.0 { + return math.sin(1.0 / x) + } else { + return 0.0 + } } fn df3(x f64, _ []f64) f64 { - if x != 0.0 { - return -math.cos(1.0 / x) / (x * x) - } else { - return 0.0 - } + if x != 0.0 { + return -math.cos(1.0 / x) / (x * x) + } else { + return 0.0 + } } fn f4(x f64, _ []f64) f64 { - return math.exp(-x * x) + return math.exp(-x * x) } fn df4(x f64, _ []f64) f64 { - return -2.0 * x * math.exp(-x * x) + return -2.0 * x * math.exp(-x * x) } fn f5(x f64, _ []f64) f64 { - return x * x + return x * x } fn df5(x f64, _ []f64) f64 { - return 2.0 * x + return 2.0 * x } fn f6(x f64, _ []f64) f64 { - return 1.0 / x + return 1.0 / x } fn df6(x f64, _ []f64) f64 { - return -1.0 / (x * x) + return -1.0 / (x * x) } // Newly added multivariable function and its partial derivatives fn f_multi(x []f64) f64 { - return x[0]*x[0] + x[1]*x[1] // f(x,y) = x^2 + y^2 + return x[0] * x[0] + x[1] * x[1] // f(x,y) = x^2 + y^2 } fn df_multi_dx(x []f64) f64 { - return 2*x[0] // ∂f/∂x = 2x + return 2 * x[0] // ∂f/∂x = 2x } fn df_multi_dy(x []f64) f64 { - return 2*x[1] // ∂f/∂y = 2y + return 2 * x[1] // ∂f/∂y = 2y } fn test_deriv() { - f1_ := func.Fn.new(f: f1) - df1_ := func.Fn.new(f: df1) - f2_ := func.Fn.new(f: f2) - df2_ := func.Fn.new(f: df2) - f3_ := func.Fn.new(f: f3) - df3_ := func.Fn.new(f: df3) - f4_ := func.Fn.new(f: f4) - df4_ := func.Fn.new(f: df4) - f5_ := func.Fn.new(f: f5) - df5_ := func.Fn.new(f: df5) - f6_ := func.Fn.new(f: f6) - df6_ := func.Fn.new(f: df6) - - assert deriv_test('central', f1_, df1_, 1.0) - assert deriv_test('forward', f1_, df1_, 1.0) - assert deriv_test('backward', f1_, df1_, 1.0) - assert deriv_test('central', f2_, df2_, 0.1) - assert deriv_test('forward', f2_, df2_, 0.1) - assert deriv_test('backward', f2_, df2_, 0.1) - assert deriv_test('central', f3_, df3_, 0.45) - assert deriv_test('forward', f3_, df3_, 0.45) - assert deriv_test('backward', f3_, df3_, 0.45) - assert deriv_test('central', f4_, df4_, 0.5) - assert deriv_test('forward', f4_, df4_, 0.5) - assert deriv_test('backward', f4_, df4_, 0.5) - assert deriv_test('central', f5_, df5_, 0.0) - assert deriv_test('forward', f5_, df5_, 0.0) - assert deriv_test('backward', f5_, df5_, 0.0) - assert deriv_test('central', f6_, df6_, 10.0) - assert deriv_test('forward', f6_, df6_, 10.0) - assert deriv_test('backward', f6_, df6_, 10.0) - - // Partial derivative test - x := [2.0, 3.0] - h := 1e-5 - - // Partial derivative with respect to x - dx, _ := partial(f_multi, x, 0, h) - assert float64.tolerance(dx, df_multi_dx(x), 1e-5) - - // Partial derivative with respect to y - dy, _ := partial(f_multi, x, 1, h) - assert float64.tolerance(dy, df_multi_dy(x), 1e-5) + f1_ := func.Fn.new(f: f1) + df1_ := func.Fn.new(f: df1) + f2_ := func.Fn.new(f: f2) + df2_ := func.Fn.new(f: df2) + f3_ := func.Fn.new(f: f3) + df3_ := func.Fn.new(f: df3) + f4_ := func.Fn.new(f: f4) + df4_ := func.Fn.new(f: df4) + f5_ := func.Fn.new(f: f5) + df5_ := func.Fn.new(f: df5) + f6_ := func.Fn.new(f: f6) + df6_ := func.Fn.new(f: df6) + + assert deriv_test('central', f1_, df1_, 1.0) + assert deriv_test('forward', f1_, df1_, 1.0) + assert deriv_test('backward', f1_, df1_, 1.0) + assert deriv_test('central', f2_, df2_, 0.1) + assert deriv_test('forward', f2_, df2_, 0.1) + assert deriv_test('backward', f2_, df2_, 0.1) + assert deriv_test('central', f3_, df3_, 0.45) + assert deriv_test('forward', f3_, df3_, 0.45) + assert deriv_test('backward', f3_, df3_, 0.45) + assert deriv_test('central', f4_, df4_, 0.5) + assert deriv_test('forward', f4_, df4_, 0.5) + assert deriv_test('backward', f4_, df4_, 0.5) + assert deriv_test('central', f5_, df5_, 0.0) + assert deriv_test('forward', f5_, df5_, 0.0) + assert deriv_test('backward', f5_, df5_, 0.0) + assert deriv_test('central', f6_, df6_, 10.0) + assert deriv_test('forward', f6_, df6_, 10.0) + assert deriv_test('backward', f6_, df6_, 10.0) + + // Partial derivative test + x := [2.0, 3.0] + h := 1e-5 + + // Partial derivative with respect to x + dx, _ := partial(f_multi, x, 0, h) + assert float64.tolerance(dx, df_multi_dx(x), 1e-5) + + // Partial derivative with respect to y + dy, _ := partial(f_multi, x, 1, h) + assert float64.tolerance(dy, df_multi_dy(x), 1e-5) } fn deriv_test(deriv_method string, f func.Fn, df func.Fn, x f64) bool { - return deriv_near_test(deriv_method, f, df, x, 1e-5) + return deriv_near_test(deriv_method, f, df, x, 1e-5) } fn deriv_near_test(deriv_method string, f func.Fn, df func.Fn, x f64, tolerance f64) bool { - expected := df.eval(x) - h := 1e-5 - result, _ := if deriv_method == 'backward' { - backward(f, x, h) - } else if deriv_method == 'forward' { - forward(f, x, h) - } else { - central(f, x, h) - } - return float64.tolerance(result, expected, tolerance) + expected := df.eval(x) + h := 1e-5 + result, _ := if deriv_method == 'backward' { + backward(f, x, h) + } else if deriv_method == 'forward' { + forward(f, x, h) + } else { + central(f, x, h) + } + return float64.tolerance(result, expected, tolerance) } - From d272ef4bd63f20c7b2cebd0c4027f523cc32c50a Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sat, 27 Jul 2024 23:05:56 +0300 Subject: [PATCH 05/15] Remove unnecessary lines --- deriv/README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/deriv/README.md b/deriv/README.md index 77ded8c80..7e8f51a42 100644 --- a/deriv/README.md +++ b/deriv/README.md @@ -81,8 +81,3 @@ This work is a spiritual descendent of the Differentiation module in [GSL](https Feel free to explore and utilize these numerical differentiation functions in your projects! 🤖📊🔬 -``` - -3. Save the file with the name `README.md`. - -Bu şekilde, `README.md` dosyanız hazır olacaktır. Başka bir yardıma ihtiyacınız olursa lütfen bildirin! From d94bc10241c6300ba729b2921349a6eaa8ca802a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 23:16:35 +0300 Subject: [PATCH 06/15] Shorten README --- deriv/README.md | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/deriv/README.md b/deriv/README.md index 7e8f51a42..fe1c73239 100644 --- a/deriv/README.md +++ b/deriv/README.md @@ -69,11 +69,7 @@ This function is equivalent to calling `deriv.forward` with a negative step-size pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) ``` -This function computes the partial derivative of a multivariable function `f` with respect to a specified variable at the point `x` using the central difference method with a step-size of `h`. The partial derivative is returned in `result` and an estimate of its absolute error is returned in `abserr`. - -The function `f` should take an array of coordinates as input and return a single value. The `variable` parameter specifies the index of the variable with respect to which the partial derivative is to be computed. - -The initial value of `h` is used to estimate an optimal step-size, based on the scaling of the truncation error and round-off error in the derivative calculation. The partial derivative is computed by converting the multivariable function into a univariate function for the specified variable and then applying the central difference method. +This function computes the partial derivative of the function `f` with respect to a specified variable at point `x` using step-size `h`. It returns the derivative in `result` and an error estimate in `abserr`. The function `f` should take an array of coordinates and return a single value. This method provides both the derivative and its error estimate. 📈 ## References and Further Reading From d6d238a334c55df101966073d44c3411b74c6791 Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sat, 27 Jul 2024 23:21:50 +0300 Subject: [PATCH 07/15] reformat deriv.v --- deriv/deriv.v | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/deriv/deriv.v b/deriv/deriv.v index b0f352dbf..60c5fb112 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -115,7 +115,7 @@ pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { } pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { - /** + /** * Computes the partial derivative of a multivariable function with respect to a specified variable. * * @param f The multivariable function for which the partial derivative is to be computed. @@ -126,21 +126,20 @@ pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { * @return A tuple containing the value of the partial derivative and the estimated error. */ - if variable < 0 || variable >= x.len { - panic('Invalid variable index') - } + if variable < 0 || variable >= x.len { + panic('Invalid variable index') + } - // Define a helper function that converts the multivariate function - // to a univariate function for the specified variable - partial_helper := func.Fn{ - f: fn [f, x, variable] (t f64, _ []f64) f64 { - mut x_new := x.clone() - x_new[variable] = t - return f(x_new) - } - } + // Define a helper function that converts the multivariate function + // to a univariate function for the specified variable + partial_helper := func.Fn{ + f: fn [f, x, variable] (t f64, _ []f64) f64 { + mut x_new := x.clone() + x_new[variable] = t + return f(x_new) + } + } - // Use the central difference method to compute the partial derivative - return central(partial_helper, x[variable], h) + // Use the central difference method to compute the partial derivative + return central(partial_helper, x[variable], h) } - From 9186f5a3d69af2d31833d2fcc39dfb209306ac7e Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sat, 27 Jul 2024 23:26:00 +0300 Subject: [PATCH 08/15] Update Readme --- deriv/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/deriv/README.md b/deriv/README.md index fe1c73239..b66312a63 100644 --- a/deriv/README.md +++ b/deriv/README.md @@ -69,7 +69,11 @@ This function is equivalent to calling `deriv.forward` with a negative step-size pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) ``` -This function computes the partial derivative of the function `f` with respect to a specified variable at point `x` using step-size `h`. It returns the derivative in `result` and an error estimate in `abserr`. The function `f` should take an array of coordinates and return a single value. This method provides both the derivative and its error estimate. 📈 +This function computes the partial derivative of the function `f` with respect to +a specified variable at point `x` using step-size `h`. It returns the derivative +in `result` and an error estimate in `abserr`. The function `f` should take an array +of coordinates and return a single value. This method provides both the derivative +and its error estimate. ## References and Further Reading From 1be4c6fa890f566d4cd9201b221f594fd04504ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 23:36:57 +0300 Subject: [PATCH 09/15] Update deriv/deriv.v Co-authored-by: Ulises Jeremias --- deriv/deriv.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deriv/deriv.v b/deriv/deriv.v index 60c5fb112..2624ce196 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -116,7 +116,7 @@ pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { /** - * Computes the partial derivative of a multivariable function with respect to a specified variable. + * partial is a function that computes the partial derivative of a multivariable function with respect to a specified variable. * * @param f The multivariable function for which the partial derivative is to be computed. * @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. From d2cb39fb84bcce3d2aa8cb62d52cc175b52b068c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 23:49:03 +0300 Subject: [PATCH 10/15] Update deriv_test.v --- deriv/deriv_test.v | 1 - 1 file changed, 1 deletion(-) diff --git a/deriv/deriv_test.v b/deriv/deriv_test.v index 4374f1244..041c53d79 100644 --- a/deriv/deriv_test.v +++ b/deriv/deriv_test.v @@ -68,7 +68,6 @@ fn df6(x f64, _ []f64) f64 { return -1.0 / (x * x) } -// Newly added multivariable function and its partial derivatives fn f_multi(x []f64) f64 { return x[0] * x[0] + x[1] * x[1] // f(x,y) = x^2 + y^2 } From caa28df95314549158ac5ec0b1ca4340976f7905 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sat, 27 Jul 2024 23:58:22 +0300 Subject: [PATCH 11/15] Update deriv.v --- deriv/deriv.v | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/deriv/deriv.v b/deriv/deriv.v index 2624ce196..41ae63293 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -1,6 +1,7 @@ module deriv import vsl.func +import vsl.errors import vsl.internal.prec import math @@ -114,20 +115,21 @@ pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { return forward(f, x, -h) } +/** +* partial is a function that computes the partial derivative of a multivariable function with respect to a specified variable. +* +* @param f The multivariable function for which the partial derivative is to be computed. +* @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. +* @param variable The index of the variable with respect to which the partial derivative is to be computed. +* @param h The step size to be used in the central difference method. +* +* @return A tuple containing the value of the partial derivative and the estimated error. +*/ pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { - /** - * partial is a function that computes the partial derivative of a multivariable function with respect to a specified variable. - * - * @param f The multivariable function for which the partial derivative is to be computed. - * @param x The point at which the partial derivative is to be computed, represented as an array of coordinates. - * @param variable The index of the variable with respect to which the partial derivative is to be computed. - * @param h The step size to be used in the central difference method. - * - * @return A tuple containing the value of the partial derivative and the estimated error. - */ + if variable < 0 || variable >= x.len { - panic('Invalid variable index') + errors.vsl_panic('Invalid variable index', .efailed) } // Define a helper function that converts the multivariate function From 40360c3fb0d2c58cd2adc805e2d9152adf4b7e8a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sun, 28 Jul 2024 00:38:46 +0300 Subject: [PATCH 12/15] run `v fmt -w deriv/deriv.v` --- deriv/deriv.v | 2 -- 1 file changed, 2 deletions(-) diff --git a/deriv/deriv.v b/deriv/deriv.v index 41ae63293..eb53c0758 100644 --- a/deriv/deriv.v +++ b/deriv/deriv.v @@ -126,8 +126,6 @@ pub fn backward(f func.Fn, x f64, h f64) (f64, f64) { * @return A tuple containing the value of the partial derivative and the estimated error. */ pub fn partial(f fn ([]f64) f64, x []f64, variable int, h f64) (f64, f64) { - - if variable < 0 || variable >= x.len { errors.vsl_panic('Invalid variable index', .efailed) } From b2741e8bf8e5df76531e342ace89bca15604fb79 Mon Sep 17 00:00:00 2001 From: "scriptalert(\"suleyman\");/script" Date: Sun, 28 Jul 2024 11:40:16 +0300 Subject: [PATCH 13/15] Added Planck Temperature --- consts/cgs.v | 2 ++ consts/cgsm.v | 2 ++ consts/mks.v | 2 ++ consts/mksa.v | 2 ++ 4 files changed, 8 insertions(+) diff --git a/consts/cgs.v b/consts/cgs.v index 512694b8a..146d88977 100644 --- a/consts/cgs.v +++ b/consts/cgs.v @@ -8,6 +8,8 @@ pub const cgs_plancks_constant_h = 6.62606896e-27 // g cm^2 / s pub const cgs_plancks_constant_hbar = 1.05457162825e-27 // g cm^2 / s +pub const cgs_planck_temperature = 1.416785e+32 // Kelvin + pub const cgs_astronomical_unit = 1.49597870691e+13 // cm pub const cgs_light_year = 9.46053620707e+17 // cm diff --git a/consts/cgsm.v b/consts/cgsm.v index 8b2d4b0d0..7a2c18aff 100644 --- a/consts/cgsm.v +++ b/consts/cgsm.v @@ -8,6 +8,8 @@ pub const cgsm_plancks_constant_h = 6.62606896e-27 // g cm^2 / s pub const cgsm_plancks_constant_hbar = 1.05457162825e-27 // g cm^2 / s +pub const cgsm_planck_temperature = 1.416785e+32 // Kelvin + pub const cgsm_astronomical_unit = 1.49597870691e+13 // cm pub const cgsm_light_year = 9.46053620707e+17 // cm diff --git a/consts/mks.v b/consts/mks.v index 0de00d50d..8fedb081d 100644 --- a/consts/mks.v +++ b/consts/mks.v @@ -8,6 +8,8 @@ pub const mks_plancks_constant_h = 6.62606896e-34 // kg m^2 / s pub const mks_plancks_constant_hbar = 1.05457162825e-34 // kg m^2 / s +pub const mks_planck_temperature = 1.416785e+32 // Kelvin + pub const mks_astronomical_unit = 1.49597870691e+11 // m pub const mks_light_year = 9.46053620707e+15 // m diff --git a/consts/mksa.v b/consts/mksa.v index a8a48d7ef..3e2da5c8a 100644 --- a/consts/mksa.v +++ b/consts/mksa.v @@ -8,6 +8,8 @@ pub const mksa_plancks_constant_h = 6.62606896e-34 // kg m^2 / s pub const mksa_plancks_constant_hbar = 1.05457162825e-34 // kg m^2 / s +pub const mksa_planck_temperature = 1.416785e+32 // Kelvin + pub const mksa_astronomical_unit = 1.49597870691e+11 // m pub const mksa_light_year = 9.46053620707e+15 // m From f397ed8f883773027951dca8c37ca2edc6c41d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:55:20 +0300 Subject: [PATCH 14/15] Update README.md --- consts/README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/consts/README.md b/consts/README.md index 4f35eeb22..669f353d0 100644 --- a/consts/README.md +++ b/consts/README.md @@ -46,6 +46,12 @@ consts.mksa_plancks_constant_hbar Planck's constant divided by `2\pi`, `\hbar`. +```console +consts.mksa_planck_temperature +``` + +Planck Temperature `T_p`. + ```console consts.num_avogadro ``` From 120712da31281b4f23800dc16525d7965bf3497d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=BCleyman=20Kaya?= <111174999+suleyman-kaya@users.noreply.github.com> Date: Sun, 28 Jul 2024 11:56:10 +0300 Subject: [PATCH 15/15] Update README.md --- consts/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/consts/README.md b/consts/README.md index 669f353d0..fa566cfdd 100644 --- a/consts/README.md +++ b/consts/README.md @@ -50,7 +50,7 @@ Planck's constant divided by `2\pi`, `\hbar`. consts.mksa_planck_temperature ``` -Planck Temperature `T_p`. +Planck temperature `T_p`. ```console consts.num_avogadro