Skip to content

Commit 8380205

Browse files
committed
2 parents 1c4c2d0 + 19114ce commit 8380205

File tree

7 files changed

+281
-5
lines changed

7 files changed

+281
-5
lines changed

Diff for: adv-math/src/equation-solvers/equations.js

+42
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,48 @@ class Equations {
1818
const x2 = (-b - sqrtDiscriminant) / (2 * a);
1919
return [x1, x2];
2020
}
21+
22+
// Method to solve a cubic equation of the form: ax^3 + bx^2 + cx + d = 0
23+
static solveCubic(a, b, c, d) {
24+
// Implementation of Cardano's method to solve cubic equations
25+
if (a === 0) {
26+
throw new Error('The coefficient of x^3 cannot be zero.');
27+
}
28+
29+
const delta0 = b * b - 3 * a * c;
30+
const delta1 = 2 * b * b * b - 9 * a * b * c + 27 * a * a * d;
31+
const C = Math.cbrt((delta1 + Math.sqrt(delta1 * delta1 - 4 * delta0 * delta0 * delta0)) / 2);
32+
const x1 = -(1 / (3 * a)) * (b + C + delta0 / C);
33+
return [x1];
34+
}
35+
36+
// Method to solve an exponential equation of the form: a^x = b
37+
static solveExponential(a, b) {
38+
if (a <= 0 || a === 1 || b <= 0) {
39+
throw new Error('Values of a and b must be positive, and a cannot be equal to 1.');
40+
}
41+
return Math.log(b) / Math.log(a);
42+
}
43+
44+
// Method to solve a logarithmic equation of the form: log_a(bx + c) = d
45+
static solveLogarithmic(a, b, c, d) {
46+
if (a <= 0 || a === 1 || b <= 0 || c < 0) {
47+
throw new Error('Values of a, b, and c must be positive, and a cannot be equal to 1.');
48+
}
49+
const logValue = d / Math.log(a);
50+
return (Math.pow(a, logValue) - c) / b;
51+
}
52+
53+
// Method to solve a system of linear equations
54+
static solveLinearSystem(a1, b1, c1, a2, b2, c2) {
55+
const determinant = a1 * b2 - a2 * b1;
56+
if (determinant === 0) {
57+
throw new Error('The system of equations has no unique solution.');
58+
}
59+
const x = (c1 * b2 - c2 * b1) / determinant;
60+
const y = (a1 * c2 - a2 * c1) / determinant;
61+
return [x, y];
62+
}
2163
}
2264

2365
module.exports = Equations;

Diff for: adv-math/src/financial/financial.js

+67-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
class Financial {
22
// Method to calculate the future value of an investment with compound interest
33
static futureValue(principal, rate, time) {
4-
const compoundInterest = principal * Math.pow(1 + rate, time);
5-
return compoundInterest;
4+
return principal * Math.pow(1 + rate, time);
65
}
76

87
// Method to calculate the compound interest earned on an investment
@@ -14,6 +13,72 @@ class Financial {
1413
static presentValue(futureValue, rate, time) {
1514
return futureValue / Math.pow(1 + rate, time);
1615
}
16+
17+
// Method to calculate the loan amortization schedule
18+
static loanAmortization(principal, rate, time) {
19+
const monthlyRate = rate / 12 / 100; // Monthly interest rate
20+
const numPayments = time * 12; // Number of monthly payments
21+
const monthlyPayment = (principal * monthlyRate) / (1 - Math.pow(1 + monthlyRate, -numPayments));
22+
23+
const amortizationSchedule = [];
24+
let remainingBalance = principal;
25+
26+
for (let month = 1; month <= numPayments; month++) {
27+
const interestPayment = remainingBalance * monthlyRate;
28+
const principalPayment = monthlyPayment - interestPayment;
29+
remainingBalance -= principalPayment;
30+
31+
amortizationSchedule.push({
32+
month,
33+
monthlyPayment,
34+
principalPayment,
35+
interestPayment,
36+
remainingBalance,
37+
});
38+
}
39+
40+
return amortizationSchedule;
41+
}
42+
43+
// Method to calculate the effective interest rate
44+
static effectiveInterestRate(principal, futureValue, time) {
45+
return Math.pow(futureValue / principal, 1 / time) - 1;
46+
}
47+
48+
// Method to convert annual interest rates to monthly
49+
static annualToMonthlyInterestRate(annualRate) {
50+
return (Math.pow(1 + annualRate, 1 / 12) - 1) * 100;
51+
}
52+
53+
// Method to calculate the net present value (NPV) of cash flows
54+
static netPresentValue(cashFlows, discountRate) {
55+
let npv = 0;
56+
for (let i = 0; i < cashFlows.length; i++) {
57+
npv += cashFlows[i] / Math.pow(1 + discountRate, i);
58+
}
59+
return npv;
60+
}
61+
62+
// Method to adjust a value for inflation
63+
static adjustForInflation(value, inflationRate, years) {
64+
return value / Math.pow(1 + inflationRate, years);
65+
}
66+
67+
// Method to calculate the periodic payment needed to reach a future value goal
68+
static calculateRequiredPaymentForFutureValue(futureValue, rate, time) {
69+
return futureValue / ((Math.pow(1 + rate, time) - 1) / rate);
70+
}
71+
72+
// Method to calculate asset depreciation
73+
static calculateDepreciation(initialValue, salvageValue, usefulLife) {
74+
return (initialValue - salvageValue) / usefulLife;
75+
}
76+
77+
// Method to calculate the total return on an investment
78+
static totalReturn(initialInvestment, finalValue, additionalInvestments) {
79+
return (finalValue - initialInvestment + additionalInvestments) / initialInvestment;
80+
}
1781
}
1882

1983
module.exports = Financial;
84+

Diff for: adv-math/src/geometry-trigonometry/geometry.js

+68
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,74 @@ class Geometry {
1818
static circleCircumference(radius) {
1919
return 2 * Math.PI * radius;
2020
}
21+
22+
// Method to calculate the area of a triangle given base and height
23+
static triangleArea(base, height) {
24+
return (base * height) / 2;
25+
}
26+
27+
// Method to calculate the volume of a sphere given its radius
28+
static sphereVolume(radius) {
29+
return (4 / 3) * Math.PI * Math.pow(radius, 3);
30+
}
31+
32+
// Method to calculate the area of an equilateral triangle given its side length
33+
static equilateralTriangleArea(side) {
34+
return (Math.sqrt(3) / 4) * Math.pow(side, 2);
35+
}
36+
//Method to calulate the area of the triangle given its side lengths
37+
static triangleArea_sides(side1, side2, side3) {
38+
const s = (side1 + side2 + side3) / 2;
39+
return Math.sqrt(s * (s - side1) * (s - side2) * (s - side3));
40+
}
41+
//Method to calulate the area of a square given its side length
42+
static squareArea(side) {
43+
return Math.pow(side, 2);
44+
}
45+
//Method to calculate the perimeter of a square given its side length
46+
static squarePerimeter(side) {
47+
return 4 * side;
48+
}
49+
50+
// Method to calculate the volume of a cube given its side length
51+
static cubeVolume(side) {
52+
return Math.pow(side, 3);
53+
}
54+
55+
// Method to calculate the volume of a rectangular prism given length, width, and height
56+
static rectangularPrismVolume(length, width, height) {
57+
return length * width * height;
58+
}
59+
60+
// Method to calculate the surface area of a rectangular prism given length, width, and height
61+
static rectangularPrismSurfaceArea(length, width, height) {
62+
return 2 * (length * width + width * height + height * length);
63+
}
64+
65+
// Method to calculate the volume of a cylinder given its radius and height
66+
static cylinderVolume(radius, height) {
67+
return Math.PI * Math.pow(radius, 2) * height;
68+
}
69+
70+
// Method to calculate the surface area of a cylinder given its radius and height
71+
static cylinderSurfaceArea(radius, height) {
72+
const baseArea = Math.PI * Math.pow(radius, 2);
73+
const lateralArea = 2 * Math.PI * radius * height;
74+
return 2 * baseArea + lateralArea;
75+
}
76+
77+
// Method to calculate the volume of a cone given its radius and height
78+
static coneVolume(radius, height) {
79+
return (1 / 3) * Math.PI * Math.pow(radius, 2) * height;
80+
}
81+
82+
// Method to calculate the surface area of a cone given its radius and height
83+
static coneSurfaceArea(radius, height) {
84+
const slantHeight = Math.sqrt(Math.pow(radius, 2) + Math.pow(height, 2));
85+
const baseArea = Math.PI * Math.pow(radius, 2);
86+
const lateralArea = Math.PI * radius * slantHeight;
87+
return baseArea + lateralArea;
88+
}
2189
}
2290

2391
module.exports = Geometry;

Diff for: adv-math/src/geometry-trigonometry/trigonometry.js

+42
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,48 @@ class Trigonometry {
7979
}
8080
return this.arctangent(1 / value);
8181
}
82+
83+
// Method to calculate the hyperbolic sine of an angle in degrees
84+
static sinh(degrees) {
85+
const radians = (degrees * Math.PI) / 180;
86+
return Math.sinh(radians);
87+
}
88+
89+
// Method to calculate the hyperbolic cosine of an angle in degrees
90+
static cosh(degrees) {
91+
const radians = (degrees * Math.PI) / 180;
92+
return Math.cosh(radians);
93+
}
94+
95+
// Method to calculate the hyperbolic tangent of an angle in degrees
96+
static tanh(degrees) {
97+
const radians = (degrees * Math.PI) / 180;
98+
return Math.tanh(radians);
99+
}
100+
101+
// Method to calculate the hyperbolic arcsine in degrees
102+
static arsinh(value) {
103+
const result = Math.asinh(value);
104+
return (result * 180) / Math.PI;
105+
}
106+
107+
// Method to calculate the hyperbolic arccosine in degrees
108+
static arcosh(value) {
109+
if (value < 1) {
110+
throw new Error('Invalid input for arcosh.');
111+
}
112+
const result = Math.acosh(value);
113+
return (result * 180) / Math.PI;
114+
}
115+
116+
// Method to calculate the hyperbolic arctangent in degrees
117+
static artanh(value) {
118+
if (value < -1 || value > 1) {
119+
throw new Error('Invalid input for artanh.');
120+
}
121+
const result = Math.atanh(value);
122+
return (result * 180) / Math.PI;
123+
}
82124
}
83125

84126
module.exports = Trigonometry;

Diff for: adv-math/src/units-conversions/units.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,19 @@ class Units {
1818
static convertTemperature(value, fromUnit, toUnit) {
1919
if (fromUnit === 'Celsius' && toUnit === 'Fahrenheit') {
2020
return (value * 9 / 5) + 32;
21+
} else if (fromUnit=='Celsius' && toUnit=='Kelvin') {
22+
return value + 273.15;
2123
} else if (fromUnit === 'Fahrenheit' && toUnit === 'Celsius') {
2224
return (value - 32) * 5 / 9;
23-
} else {
25+
} else if (fromUnit=='Fahrenheit' && toUnit=='Kelvin') {
26+
return (value + 459.67) * 5 / 9;
27+
} else if (fromUnit=='Kelvin' && toUnit=='Celsius') {
28+
return value - 273.15;
29+
} else if (fromUnit=='Kelvin' && toUnit=='Fahrenheit') {
30+
return (value * 9 / 5) - 459.67;
31+
}
32+
33+
else {
2434
throw new Error('Invalid temperature unit conversion.');
2535
}
2636
}

Diff for: adv-math/tests/geometry-trigonometry.test.js

+39-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,45 @@ describe('Geometry', () => {
1717
test('calculates the circumference of a circle', () => {
1818
expect(Geometry.circleCircumference(3)).toBeCloseTo(18.850, 3);
1919
});
20-
20+
test('calculates the area of a triangle', () => {
21+
expect(Geometry.triangleArea(3, 4)).toBe(6);
22+
});
23+
test('calculates the volume of a sphere', () => {
24+
expect(Geometry.sphereVolume(3)).toBeCloseTo(113.097, 3);
25+
});
26+
test('calculates the area of an equilateral triangle', () => {
27+
expect(Geometry.equilateralTriangleArea(3)).toBeCloseTo(3.897, 3);
28+
});
29+
test('calculates the area of a triangle given its side lengths', () => {
30+
expect(Geometry.triangleArea_sides(3, 4, 5)).toBe(6);
31+
});
32+
test('calculates the area of a square given its side length', () => {
33+
expect(Geometry.squareArea(3)).toBe(9);
34+
});
35+
test('calculates the perimeter of a square given its side length', () => {
36+
expect(Geometry.squarePerimeter(3)).toBe(12);
37+
});
38+
test('calculates the volume of a cube given its side length', () => {
39+
expect(Geometry.cubeVolume(3)).toBe(27);
40+
});
41+
test('calculates the volume of a rectangular prism given length, width, and height', () => {
42+
expect(Geometry.rectangularPrismVolume(3, 4, 5)).toBe(60);
43+
});
44+
test('calculates the surface area of a rectangular prism given length, width, and height', () => {
45+
expect(Geometry.rectangularPrismSurfaceArea(3, 4, 5)).toBe(94);
46+
});
47+
test('calculates the volume of a cylinder given radius and height', () => {
48+
expect(Geometry.cylinderVolume(3, 5)).toBeCloseTo(141.371, 3);
49+
});
50+
test('calculates the surface area of a cylinder given radius and height', () => {
51+
expect(Geometry.cylinderSurfaceArea(3, 5)).toBeCloseTo(150.796, 3);
52+
});
53+
test('calculates the volume of a cone given radius and height', () => {
54+
expect(Geometry.coneVolume(3, 5)).toBeCloseTo(47.123, 3);
55+
});
56+
test('calculates the surface area of a cone given radius and height', () => {
57+
expect(Geometry.coneSurfaceArea(3, 5)).toBeCloseTo(83.229, 3);
58+
});
2159
// Add more test cases as needed
2260
});
2361

Diff for: adv-math/tests/units-conversions.test.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,21 @@ describe('Units', () => {
1212
test('converts Celsius to Fahrenheit', () => {
1313
expect(Units.convertTemperature(25, 'Celsius', 'Fahrenheit')).toBeCloseTo(77, 1);
1414
});
15-
15+
test('converts Celsius to Kelvin', () => {
16+
expect(Units.convertTemperature(25, 'Celsius', 'Kelvin')).toBeCloseTo(298.15, 1);
17+
});
18+
test('converts Fahrenheit to Kelvin', () => {
19+
expect(Units.convertTemperature(68, 'Fahrenheit', 'Kelvin')).toBeCloseTo(293.15, 1);
20+
});
1621
test('converts Fahrenheit to Celsius', () => {
1722
expect(Units.convertTemperature(68, 'Fahrenheit', 'Celsius')).toBeCloseTo(20, 1);
1823
});
24+
test('converts Kelvin to Celsius', () => {
25+
expect(Units.convertTemperature(300, 'Kelvin', 'Celsius')).toBeCloseTo(26.85, 1);
26+
});
27+
test('converts Kelvin to Fahrenheit', () => {
28+
expect(Units.convertTemperature(300, 'Kelvin', 'Fahrenheit')).toBeCloseTo(80.33, 1);
29+
});
1930

2031
// Add more test cases as needed
2132
});

0 commit comments

Comments
 (0)