From 2b274a98c898969ad5b753ed48b812617f6a709d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Rafael=20L=C3=A1zaro=20Nevado?= <119618710+Pedrop19@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:42:09 +0200 Subject: [PATCH 1/5] Update trigonometry.js --- .../src/geometry-trigonometry/trigonometry.js | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/adv-math/src/geometry-trigonometry/trigonometry.js b/adv-math/src/geometry-trigonometry/trigonometry.js index a803bae..0f1c2e4 100644 --- a/adv-math/src/geometry-trigonometry/trigonometry.js +++ b/adv-math/src/geometry-trigonometry/trigonometry.js @@ -79,6 +79,48 @@ class Trigonometry { } return this.arctangent(1 / value); } + + // Method to calculate the hyperbolic sine of an angle in degrees + static sinh(degrees) { + const radians = (degrees * Math.PI) / 180; + return Math.sinh(radians); + } + + // Method to calculate the hyperbolic cosine of an angle in degrees + static cosh(degrees) { + const radians = (degrees * Math.PI) / 180; + return Math.cosh(radians); + } + + // Method to calculate the hyperbolic tangent of an angle in degrees + static tanh(degrees) { + const radians = (degrees * Math.PI) / 180; + return Math.tanh(radians); + } + + // Method to calculate the hyperbolic arcsine in degrees + static arsinh(value) { + const result = Math.asinh(value); + return (result * 180) / Math.PI; + } + + // Method to calculate the hyperbolic arccosine in degrees + static arcosh(value) { + if (value < 1) { + throw new Error('Invalid input for arcosh.'); + } + const result = Math.acosh(value); + return (result * 180) / Math.PI; + } + + // Method to calculate the hyperbolic arctangent in degrees + static artanh(value) { + if (value < -1 || value > 1) { + throw new Error('Invalid input for artanh.'); + } + const result = Math.atanh(value); + return (result * 180) / Math.PI; + } } module.exports = Trigonometry; From 8abe64fa788df137a999990b4a354c17fcab3a4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Rafael=20L=C3=A1zaro=20Nevado?= <119618710+Pedrop19@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:44:44 +0200 Subject: [PATCH 2/5] Update geometry.js --- .../src/geometry-trigonometry/geometry.js | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/adv-math/src/geometry-trigonometry/geometry.js b/adv-math/src/geometry-trigonometry/geometry.js index 38a76cd..6bd89c2 100644 --- a/adv-math/src/geometry-trigonometry/geometry.js +++ b/adv-math/src/geometry-trigonometry/geometry.js @@ -18,6 +18,61 @@ class Geometry { static circleCircumference(radius) { return 2 * Math.PI * radius; } + + // Method to calculate the area of a triangle given base and height + static triangleArea(base, height) { + return (base * height) / 2; + } + + // Method to calculate the volume of a sphere given its radius + static sphereVolume(radius) { + return (4 / 3) * Math.PI * Math.pow(radius, 3); + } + + // Method to calculate the area of an equilateral triangle given its side length + static equilateralTriangleArea(side) { + return (Math.sqrt(3) / 4) * Math.pow(side, 2); + } + + // Method to calculate the volume of a cube given its side length + static cubeVolume(side) { + return Math.pow(side, 3); + } + + // Method to calculate the volume of a rectangular prism given length, width, and height + static rectangularPrismVolume(length, width, height) { + return length * width * height; + } + + // Method to calculate the surface area of a rectangular prism given length, width, and height + static rectangularPrismSurfaceArea(length, width, height) { + return 2 * (length * width + width * height + height * length); + } + + // Method to calculate the volume of a cylinder given its radius and height + static cylinderVolume(radius, height) { + return Math.PI * Math.pow(radius, 2) * height; + } + + // Method to calculate the surface area of a cylinder given its radius and height + static cylinderSurfaceArea(radius, height) { + const baseArea = Math.PI * Math.pow(radius, 2); + const lateralArea = 2 * Math.PI * radius * height; + return 2 * baseArea + lateralArea; + } + + // Method to calculate the volume of a cone given its radius and height + static coneVolume(radius, height) { + return (1 / 3) * Math.PI * Math.pow(radius, 2) * height; + } + + // Method to calculate the surface area of a cone given its radius and height + static coneSurfaceArea(radius, height) { + const slantHeight = Math.sqrt(Math.pow(radius, 2) + Math.pow(height, 2)); + const baseArea = Math.PI * Math.pow(radius, 2); + const lateralArea = Math.PI * radius * slantHeight; + return baseArea + lateralArea; + } } module.exports = Geometry; From ffa7d0ae66e3dd20b052e40c643eaac627e3cf08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Rafael=20L=C3=A1zaro=20Nevado?= <119618710+Pedrop19@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:43:00 +0200 Subject: [PATCH 3/5] Update equations.js --- adv-math/src/equation-solvers/equations.js | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/adv-math/src/equation-solvers/equations.js b/adv-math/src/equation-solvers/equations.js index dae5bab..5f5c2ff 100644 --- a/adv-math/src/equation-solvers/equations.js +++ b/adv-math/src/equation-solvers/equations.js @@ -18,6 +18,48 @@ class Equations { const x2 = (-b - sqrtDiscriminant) / (2 * a); return [x1, x2]; } + + // Method to solve a cubic equation of the form: ax^3 + bx^2 + cx + d = 0 + static solveCubic(a, b, c, d) { + // Implementation of Cardano's method to solve cubic equations + if (a === 0) { + throw new Error('The coefficient of x^3 cannot be zero.'); + } + + const delta0 = b * b - 3 * a * c; + const delta1 = 2 * b * b * b - 9 * a * b * c + 27 * a * a * d; + const C = Math.cbrt((delta1 + Math.sqrt(delta1 * delta1 - 4 * delta0 * delta0 * delta0)) / 2); + const x1 = -(1 / (3 * a)) * (b + C + delta0 / C); + return [x1]; + } + + // Method to solve an exponential equation of the form: a^x = b + static solveExponential(a, b) { + if (a <= 0 || a === 1 || b <= 0) { + throw new Error('Values of a and b must be positive, and a cannot be equal to 1.'); + } + return Math.log(b) / Math.log(a); + } + + // Method to solve a logarithmic equation of the form: log_a(bx + c) = d + static solveLogarithmic(a, b, c, d) { + if (a <= 0 || a === 1 || b <= 0 || c < 0) { + throw new Error('Values of a, b, and c must be positive, and a cannot be equal to 1.'); + } + const logValue = d / Math.log(a); + return (Math.pow(a, logValue) - c) / b; + } + + // Method to solve a system of linear equations + static solveLinearSystem(a1, b1, c1, a2, b2, c2) { + const determinant = a1 * b2 - a2 * b1; + if (determinant === 0) { + throw new Error('The system of equations has no unique solution.'); + } + const x = (c1 * b2 - c2 * b1) / determinant; + const y = (a1 * c2 - a2 * c1) / determinant; + return [x, y]; + } } module.exports = Equations; From 1e9bba0729e3c18715e22bba896d90dde94c681f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20Rafael=20L=C3=A1zaro=20Nevado?= <119618710+Pedrop19@users.noreply.github.com> Date: Thu, 5 Oct 2023 16:46:49 +0200 Subject: [PATCH 4/5] Update financial.js --- adv-math/src/financial/financial.js | 69 ++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/adv-math/src/financial/financial.js b/adv-math/src/financial/financial.js index 2352e11..a4e1af4 100644 --- a/adv-math/src/financial/financial.js +++ b/adv-math/src/financial/financial.js @@ -1,8 +1,7 @@ class Financial { // Method to calculate the future value of an investment with compound interest static futureValue(principal, rate, time) { - const compoundInterest = principal * Math.pow(1 + rate, time); - return compoundInterest; + return principal * Math.pow(1 + rate, time); } // Method to calculate the compound interest earned on an investment @@ -14,6 +13,72 @@ class Financial { static presentValue(futureValue, rate, time) { return futureValue / Math.pow(1 + rate, time); } + + // Method to calculate the loan amortization schedule + static loanAmortization(principal, rate, time) { + const monthlyRate = rate / 12 / 100; // Monthly interest rate + const numPayments = time * 12; // Number of monthly payments + const monthlyPayment = (principal * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -numPayments)); + + const amortizationSchedule = []; + let remainingBalance = principal; + + for (let month = 1; month <= numPayments; month++) { + const interestPayment = remainingBalance * monthlyRate; + const principalPayment = monthlyPayment - interestPayment; + remainingBalance -= principalPayment; + + amortizationSchedule.push({ + month, + monthlyPayment, + principalPayment, + interestPayment, + remainingBalance, + }); + } + + return amortizationSchedule; + } + + // Method to calculate the effective interest rate + static effectiveInterestRate(principal, futureValue, time) { + return Math.pow(futureValue / principal, 1 / time) - 1; + } + + // Method to convert annual interest rates to monthly + static annualToMonthlyInterestRate(annualRate) { + return (Math.pow(1 + annualRate, 1 / 12) - 1) * 100; + } + + // Method to calculate the net present value (NPV) of cash flows + static netPresentValue(cashFlows, discountRate) { + let npv = 0; + for (let i = 0; i < cashFlows.length; i++) { + npv += cashFlows[i] / Math.pow(1 + discountRate, i); + } + return npv; + } + + // Method to adjust a value for inflation + static adjustForInflation(value, inflationRate, years) { + return value / Math.pow(1 + inflationRate, years); + } + + // Method to calculate the periodic payment needed to reach a future value goal + static calculateRequiredPaymentForFutureValue(futureValue, rate, time) { + return futureValue / ((Math.pow(1 + rate, time) - 1) / rate); + } + + // Method to calculate asset depreciation + static calculateDepreciation(initialValue, salvageValue, usefulLife) { + return (initialValue - salvageValue) / usefulLife; + } + + // Method to calculate the total return on an investment + static totalReturn(initialInvestment, finalValue, additionalInvestments) { + return (finalValue - initialInvestment + additionalInvestments) / initialInvestment; + } } module.exports = Financial; + From 8ad1e3eb81773360899bb8d601930af103a4b8a2 Mon Sep 17 00:00:00 2001 From: saikowsik23 Date: Thu, 5 Oct 2023 18:01:41 +0200 Subject: [PATCH 5/5] made changes to unit-conversions geometry (even in tests) --- .../src/geometry-trigonometry/geometry.js | 13 ++++++ adv-math/src/units-conversions/units.js | 12 +++++- adv-math/tests/geometry-trigonometry.test.js | 40 ++++++++++++++++++- adv-math/tests/units-conversions.test.js | 13 +++++- 4 files changed, 75 insertions(+), 3 deletions(-) diff --git a/adv-math/src/geometry-trigonometry/geometry.js b/adv-math/src/geometry-trigonometry/geometry.js index 6bd89c2..10d253e 100644 --- a/adv-math/src/geometry-trigonometry/geometry.js +++ b/adv-math/src/geometry-trigonometry/geometry.js @@ -33,6 +33,19 @@ class Geometry { static equilateralTriangleArea(side) { return (Math.sqrt(3) / 4) * Math.pow(side, 2); } + //Method to calulate the area of the triangle given its side lengths + static triangleArea_sides(side1, side2, side3) { + const s = (side1 + side2 + side3) / 2; + return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3)); + } + //Method to calulate the area of a square given its side length + static squareArea(side) { + return Math.pow(side, 2); + } + //Method to calculate the perimeter of a square given its side length + static squarePerimeter(side) { + return 4 * side; + } // Method to calculate the volume of a cube given its side length static cubeVolume(side) { diff --git a/adv-math/src/units-conversions/units.js b/adv-math/src/units-conversions/units.js index a6f8b6d..e769ce2 100644 --- a/adv-math/src/units-conversions/units.js +++ b/adv-math/src/units-conversions/units.js @@ -18,9 +18,19 @@ class Units { static convertTemperature(value, fromUnit, toUnit) { if (fromUnit === 'Celsius' && toUnit === 'Fahrenheit') { return (value * 9 / 5) + 32; + } else if (fromUnit=='Celsius' && toUnit=='Kelvin') { + return value + 273.15; } else if (fromUnit === 'Fahrenheit' && toUnit === 'Celsius') { return (value - 32) * 5 / 9; - } else { + } else if (fromUnit=='Fahrenheit' && toUnit=='Kelvin') { + return (value + 459.67) * 5 / 9; + } else if (fromUnit=='Kelvin' && toUnit=='Celsius') { + return value - 273.15; + } else if (fromUnit=='Kelvin' && toUnit=='Fahrenheit') { + return (value * 9 / 5) - 459.67; + } + + else { throw new Error('Invalid temperature unit conversion.'); } } diff --git a/adv-math/tests/geometry-trigonometry.test.js b/adv-math/tests/geometry-trigonometry.test.js index 768c8ed..ab4113c 100644 --- a/adv-math/tests/geometry-trigonometry.test.js +++ b/adv-math/tests/geometry-trigonometry.test.js @@ -17,7 +17,45 @@ describe('Geometry', () => { test('calculates the circumference of a circle', () => { expect(Geometry.circleCircumference(3)).toBeCloseTo(18.850, 3); }); - + test('calculates the area of a triangle', () => { + expect(Geometry.triangleArea(3, 4)).toBe(6); + }); + test('calculates the volume of a sphere', () => { + expect(Geometry.sphereVolume(3)).toBeCloseTo(113.097, 3); + }); + test('calculates the area of an equilateral triangle', () => { + expect(Geometry.equilateralTriangleArea(3)).toBeCloseTo(3.897, 3); + }); + test('calculates the area of a triangle given its side lengths', () => { + expect(Geometry.triangleArea_sides(3, 4, 5)).toBe(6); + }); + test('calculates the area of a square given its side length', () => { + expect(Geometry.squareArea(3)).toBe(9); + }); + test('calculates the perimeter of a square given its side length', () => { + expect(Geometry.squarePerimeter(3)).toBe(12); + }); + test('calculates the volume of a cube given its side length', () => { + expect(Geometry.cubeVolume(3)).toBe(27); + }); + test('calculates the volume of a rectangular prism given length, width, and height', () => { + expect(Geometry.rectangularPrismVolume(3, 4, 5)).toBe(60); + }); + test('calculates the surface area of a rectangular prism given length, width, and height', () => { + expect(Geometry.rectangularPrismSurfaceArea(3, 4, 5)).toBe(94); + }); + test('calculates the volume of a cylinder given radius and height', () => { + expect(Geometry.cylinderVolume(3, 5)).toBeCloseTo(141.371, 3); + }); + test('calculates the surface area of a cylinder given radius and height', () => { + expect(Geometry.cylinderSurfaceArea(3, 5)).toBeCloseTo(150.796, 3); + }); + test('calculates the volume of a cone given radius and height', () => { + expect(Geometry.coneVolume(3, 5)).toBeCloseTo(47.123, 3); + }); + test('calculates the surface area of a cone given radius and height', () => { + expect(Geometry.coneSurfaceArea(3, 5)).toBeCloseTo(83.229, 3); + }); // Add more test cases as needed }); diff --git a/adv-math/tests/units-conversions.test.js b/adv-math/tests/units-conversions.test.js index 25eaba4..414cbde 100644 --- a/adv-math/tests/units-conversions.test.js +++ b/adv-math/tests/units-conversions.test.js @@ -12,10 +12,21 @@ describe('Units', () => { test('converts Celsius to Fahrenheit', () => { expect(Units.convertTemperature(25, 'Celsius', 'Fahrenheit')).toBeCloseTo(77, 1); }); - + test('converts Celsius to Kelvin', () => { + expect(Units.convertTemperature(25, 'Celsius', 'Kelvin')).toBeCloseTo(298.15, 1); + }); + test('converts Fahrenheit to Kelvin', () => { + expect(Units.convertTemperature(68, 'Fahrenheit', 'Kelvin')).toBeCloseTo(293.15, 1); + }); test('converts Fahrenheit to Celsius', () => { expect(Units.convertTemperature(68, 'Fahrenheit', 'Celsius')).toBeCloseTo(20, 1); }); + test('converts Kelvin to Celsius', () => { + expect(Units.convertTemperature(300, 'Kelvin', 'Celsius')).toBeCloseTo(26.85, 1); + }); + test('converts Kelvin to Fahrenheit', () => { + expect(Units.convertTemperature(300, 'Kelvin', 'Fahrenheit')).toBeCloseTo(80.33, 1); + }); // Add more test cases as needed });