Why is my percentage calculation failing? - math

I tried to calculate the percentage of one value (total sales for one item) compared to another (total sales for all items) based on what it says here and came up with this code:
private double GetPercentageOfItem(decimal totPrice, decimal grandTotalPrice)
{
if ((totPrice <= 0.0M) || (grandTotalPrice <= 0.0M))
{
return 0.0;
}
if (totPrice == grandTotalPrice)
{
return 100.0;
}
//First: work out the difference (increase) between the two numbers you are comparing.
//Increase = New Number - Original Number.
double diff = Convert.ToDouble(grandTotalPrice) - Convert.ToDouble(totPrice);
//Then: divide the increase by the original number and multiply the answer by 100.
double prcntg = diff / Convert.ToDouble(totPrice);
//% increase = Increase ÷ Original Number × 100.
return prcntg*100;
}
grandTotalPrice is the sum of all totalSales values in a dataset:
decimal grandTotalPrice = 0.0M;
. . .
foreach (DataRow productUsageByMonthDataRow in dtUsage.Rows)
{
grandTotalPrice = grandTotalPrice + Convert.ToDecimal(productUsageByMonthDataRow["TotalPrice"]);
}
totPrice are the individual TotalPrice values.
Instead of getting values I expect, though, such as 3.something percent (or 2.N, or 1.N, or 0.N), I'm getting outrageous values such as "318940.70340793" in each Percentage member, which is assigned like so:
foreach (DataRow productUsageByMonthDataRow in dtUsage.Rows)
{
. . .
Decimal totPrice
Convert.ToDecimal(productUsageByMonthDataRow["TotalPrice"]);
. . .
var pupd = new ProduceUsagePivotData
{
ItemCode = itemCode,
ItemDescription = desc,
Unit = unit,
MonthYear = monthYear,
Quantity = qty,
TotalPrice = totPrice,
IsContractItem = contractItem,
Percentage = GetPercentageOfItem(totPrice, grandTotalPrice)
};
. . .
In the data I am testing, grandTotalPrice is 687149.867, and the first Total Sales value is 215.38; so how does that equate to 318940.70340793?
UPDATE
Thanks to the answers of several (I accepted the first one), as well as my own inimitable flourishes, curlicues, and baroque gingerbreading, I ended up with this:
private double GetPercentageOfItem(decimal totPrice, decimal grandTotalPrice)
{
if ((totPrice <= 0.0M) || (grandTotalPrice <= 0.0M))
{
return 0.0;
}
if (totPrice == grandTotalPrice)
{
return 100.0;
}
double d = Convert.ToDouble(totPrice) / Convert.ToDouble(grandTotalPrice) * 100;
return Math.Round(d, 2);
}

Based on what you are saying you expect... It seems as though you are looking for what percent item(1) is of the total.
For example if Item1 = $10 and the totalCost = $100
Then the percent you are looking for is 10%?
In this case you simply need to divide the the itemCost by the totalcost and multiply by 100
var percent = itemCost / totalCost * 100;
(10 / 100 * 100 ) = 10%
If you are in fact looking for the percent increase then the number you are getting is correct.
Think of when someone says "We have seen a 200% increase" what this really means is the value has doubled... So if we look at the number you got 318940.70340793%
If we divide this by 100, we get 3189.407.
3189 * 215 = 687149.867 (approx)
So if you are looking for percent increase than the values you are getting are correct, however if you are looking for the percent cost of Item1 compared with the GrandTotal then use my above formula.
Hope this helps!

Related

How to increase a number for a certain percentage (say %10) expotential number of times (say 20) and then decrease it to base value again?

I basically have a number, say 100.
I can increase it by 10 percent every time. So, :
1st run it would become 110,
2nd 121,
3rd 133 and so on.
I can have count of how much the value was increased. But how to expotentialy decrease the amount knowing the number of times it has been increased back to 100?
Is there a way to do it with simple math op like ** instead of looping the current value amount of times it has been altered by 10 percents?
I know I can just store it in additionl column like base_number=100 or something when I need the basic value, but I would like to know if its possible to do by one-liner calculations?
So your basic question is, how do you invert and find x_0 given a known n and:
x_n = x_0 * 1.1^n
Looks like we can simply divide through by 1.1^n
x_n/(1.1^n) = x_0
So you can either calculate 1.1^n with pow(1.1, n) and divide x_n (your "increased" value) by that, or just loop and reduce like you increased:
//1.
$original = $increased/pow(1.1, n);
//2.
$original = $increased;
for ($i = 0; $i < n; $i++) {
$original = $original / 1.1;
}
So in your example, let's say our $increased is known to be 133, and n=3. Then using the first method:
$original = 133 / (1.1^3) = 133 / 1.33 = 100
Let's make a simple example and try to find a formula :
100 * 1.10 = 110;
110 * 1.10 = 121;
121 * 1.10 = 133.1;
So right now we have :
basic_number (will be bn) * increase_value (will be iv) = basic_number2;
bn2 * iv = bn3;
bn3 * iv = bn4;
We can write it too :
bn * iv = bn2;
bn * iv * iv = bn3;
bn * iv * iv * iv = bn4;
And so we have the beginning of a formula :
bn * iv^3 = bn4;
Now what you will have as data according to your post is :
X : the number of increase
bnX : the basic number increase X time
iv : the increase value
And you want to find bn according to those value :
bn * iv^X = bnX;
bn = bnX / iv^X;
bn = bnX / (iv * iv * iv ... * iv); // X time
So with PHP it could look like this :
$X = /* the number of incease */;
$bnX = /* the basic number increase X time */;
$iv = /* the increase value */;
for($i = 0; $i < $X; $i++) {
$bnX = $bnX / $iv;
}
This way you will if you echo $bnX; at the end of the loop, you should get your basic number !
You can try to make a php formula to do it and use it every time :
// 1/ Using a loop
function getBasicNumber($bnX, $X, $iv) {
for($i = 0; $i < $X; $i++) {
$bnX = $bnX / $iv;
}
return $bnX;
}
EDIT
// 2/ Using pow
function getBasicNumber($bnX, $X, $iv) {
return $bnX / pow($X, $iv);
}
// 3/ Using '**'
function getBasicNumber($bnX, $X, $iv) {
return $bnX / $X**$iv;
}
This way you just have to do :
echo getBasicNumber(133.1, 3, 1.10); // 100 here for example
Hope it's clear? But still, it's more a maths problem than a programming one

Using spreadsheet to count consecutive cells

So I want to use Google spreadsheet to find how many times does five consecutive cells have a value greater than a given value in a row,but one cell cant be a part of two set of consecutive cells.For example i want to count the number of times a particular item was bought in a month for consecutive five days but if it was bought for 7 days at a stretch it will only be counted as one whereas if it is multiple of five it will be counted as many multiples of five.
For Ex:If cells 1-5 have a value greater than the given value it should give me a count of 1, but if cells 1-9 also are greater than the given value even then it should give me count of 1 but if 1-10 have a value greater than the given value then it should give me a count of 2.I hope this was clear.
I want to write this code in Google Drive using custom function, I tried writing a code in C.
*
int x; //no. of rows
int y; //no. of columns
int arr[x][y]; //array to store numbers
int count[x];
int i,j,k; //for loops
for(i=0;i<x;i++) //set count to 0 for all rows
count[x]=0;
for(i=0;i<x;i++)
{
for(j=0;j<y;j++)
{
for(k=1;k<=5, j<y;k++, j++)
{
if(!arr[i][j]>0)
{
break;
}
else if(k==5 && arr[i][j]!<1)
{
count[i]++;
j--;
}
}
}
}
//display the count array now to see result.
*
You can do this without writing code. That's kinda the purpose of a spreadsheet.
You have one column, say column A, with the values.
In the next column, start a counter that increments each row if the value in the first column is >= your preset value, and reset the counter if not. The formula would be something like (for cell B2)
=IF(A2>=$E$1,B1+1,0)
In the next column, calculate the multiples of 5. For cell C2:
=IF(MOD(B2,5)=0,C1+1,C1)
Copy those cells down to the bottom of the list in column A, and the last value will be the count of values that exceeded cell $e1 a multiple of 5 consecutive times.
Another way using native Sheets functions:
=ArrayFormula((ROWS(A:A)-LEN(REGEXREPLACE(CONCATENATE(LEFT(A:A>=1)),"TTTTT","")))/5)
and using a custom function:
function countGroups(range, comparisonValue, groupSize) {
var v = comparisonValue || 1; // default to comparing to 1 if not specified
var n = groupSize || 5; // default to groups of 5 if not specified
var count = 0, counter = 0;
for (var i = 0, length = range.length; i < length; i++) {
if (range[i][0] >= v) {
counter++;
if (counter == n) {
counter = 0;
count++;
}
}
else
counter = 0;
}
return count;
}

Divide and Conquer Recursion

I am just trying to understand how the recursion works in this example, and would appreciate it if somebody could break this down for me. I have the following algorithm which basically returns the maximum element in an array:
int MaximumElement(int array[], int index, int n)
{
int maxval1, maxval2;
if ( n==1 ) return array[index];
maxval1 = MaximumElement(array, index, n/2);
maxval2 = MaximumElement(array, index+(n/2), n-(n/2));
if (maxval1 > maxval2)
return maxval1;
else
return maxval2;
}
I am not able to understand how the recursive calls work here. Does the first recursive call always get executed when the second call is being made? I really appreciate it if someone could please explain this to me. Many thanks!
Code comments embedded:
// the names index and n are misleading, it would be better if we named it:
// startIndex and rangeToCheck
int MaximumElement(int array[], int startIndex, int rangeToCheck)
{
int maxval1, maxval2;
// when the range to check is only one cell - return it as the maximum
// that's the base-case of the recursion
if ( rangeToCheck==1 ) return array[startIndex];
// "divide" by checking the range between the index and the first "half" of the range
System.out.println("index = "+startIndex+"; rangeToCheck/2 = " + rangeToCheck/2);
maxval1 = MaximumElement(array, startIndex, rangeToCheck/2);
// check the second "half" of the range
System.out.println("index = "+startIndex+"; rangeToCheck-(rangeToCheck/2 = " + (rangeToCheck-(rangeToCheck/2)));
maxval2 = MaximumElement(array, startIndex+(rangeToCheck/2), rangeToCheck-(rangeToCheck/2));
// and now "Conquer" - compare the 2 "local maximums" that we got from the last step
// and return the bigger one
if (maxval1 > maxval2)
return maxval1;
else
return maxval2;
}
Example of usage:
int[] arr = {5,3,4,8,7,2};
int big = MaximumElement(arr,0,arr.length-1);
System.out.println("big = " + big);
OUTPUT:
index = 0; rangeToCheck/2 = 2
index = 0; rangeToCheck/2 = 1
index = 0; rangeToCheck-(rangeToCheck/2 = 1
index = 0; rangeToCheck-(rangeToCheck/2 = 3
index = 2; rangeToCheck/2 = 1
index = 2; rangeToCheck-(rangeToCheck/2 = 2
index = 3; rangeToCheck/2 = 1
index = 3; rangeToCheck-(rangeToCheck/2 = 1
big = 8
What is happening here is that both recursive calls are being made, one after another. The first one searches have the array and returns the max, the second searches the other half and returns the max. Then the two maxes are compared and the bigger max is returned.
Yes. What you have guessed is right. Out of the two recursive calls MaximumElement(array, index, n/2) and MaximumElement(array, index+(n/2), n-(n/2)), the first call is repeatedly carried out until the call is made with a single element of the array. Then the two elements are compared and the largest is returned. Then this comparison process is continued until the largest element is returned.

Calculate date from a number

I need a method which would give me the number of hours and minutes from any random number.For example if the random number is 500 i would like to have information as 5 hrs and 0 minutes.Another example is 2359 is 23 hrs 59 minutes.The random number is entered by the user and i am only concerned with the hours and minutes(not seconds).I need not even worry about rounding off of minutes .So i wrote this method ,which to me is not efficient.Can any one suggest a better way of doing it ?or is this good enough?
private void calculateDateTime(int someNumber){
if(someNumber<=0){
return;
}
String number = Integer.toString(someNumber);
String hrs ="";
String mins ="00";
if(number.length()>4){
hrs =number.substring(0, 2);
mins = number.substring(2,4);
}
else{
float f =((float)someNumber)/100;
String s = Float.toString(f);
String [] splitArray = s.split("\\.");
if(splitArray.length>1) {
hrs = splitArray[0];
mins = splitArray[1];
}
}
int hr = Integer.valueOf(hrs);
int min = Integer.valueOf(mins);
if(hr>=24||min>=60){
return;
}
Thats how i am getting the hr and mins respectively.Suggest me a better approach if you have one.
Thanks
Pad the input string with zeros until length is 4 and then spilt the string in the middle?
Maybe:
int hours = someNumber / 100;
int minutes = someNumber % 100;
if(hours >= 24 || minutes >= 60) {
//Do whatever
}
If you want your values to be repeatable, I would use the passed in value as the seed into a Random generator.
Random r = new Random(someNumber);
int hr = r.nextInt(24);
int min = r.nextInt(60);

How to scale down a range of numbers with a known min and max value

So I am trying to figure out how to take a range of numbers and scale the values down to fit a range. The reason for wanting to do this is that I am trying to draw ellipses in a java swing jpanel. I want the height and width of each ellipse to be in a range of say 1-30. I have methods that find the minimum and maximum values from my data set, but I won't have the min and max until runtime. Is there an easy way to do this?
Let's say you want to scale a range [min,max] to [a,b]. You're looking for a (continuous) function that satisfies
f(min) = a
f(max) = b
In your case, a would be 1 and b would be 30, but let's start with something simpler and try to map [min,max] into the range [0,1].
Putting min into a function and getting out 0 could be accomplished with
f(x) = x - min ===> f(min) = min - min = 0
So that's almost what we want. But putting in max would give us max - min when we actually want 1. So we'll have to scale it:
x - min max - min
f(x) = --------- ===> f(min) = 0; f(max) = --------- = 1
max - min max - min
which is what we want. So we need to do a translation and a scaling. Now if instead we want to get arbitrary values of a and b, we need something a little more complicated:
(b-a)(x - min)
f(x) = -------------- + a
max - min
You can verify that putting in min for x now gives a, and putting in max gives b.
You might also notice that (b-a)/(max-min) is a scaling factor between the size of the new range and the size of the original range. So really we are first translating x by -min, scaling it to the correct factor, and then translating it back up to the new minimum value of a.
Here's some JavaScript for copy-paste ease (this is irritate's answer):
function scaleBetween(unscaledNum, minAllowed, maxAllowed, min, max) {
return (maxAllowed - minAllowed) * (unscaledNum - min) / (max - min) + minAllowed;
}
Applied like so, scaling the range 10-50 to a range between 0-100.
var unscaledNums = [10, 13, 25, 28, 43, 50];
var maxRange = Math.max.apply(Math, unscaledNums);
var minRange = Math.min.apply(Math, unscaledNums);
for (var i = 0; i < unscaledNums.length; i++) {
var unscaled = unscaledNums[i];
var scaled = scaleBetween(unscaled, 0, 100, minRange, maxRange);
console.log(scaled.toFixed(2));
}
0.00, 18.37, 48.98, 55.10, 85.71, 100.00
Edit:
I know I answered this a long time ago, but here's a cleaner function that I use now:
Array.prototype.scaleBetween = function(scaledMin, scaledMax) {
var max = Math.max.apply(Math, this);
var min = Math.min.apply(Math, this);
return this.map(num => (scaledMax-scaledMin)*(num-min)/(max-min)+scaledMin);
}
Applied like so:
[-4, 0, 5, 6, 9].scaleBetween(0, 100);
[0, 30.76923076923077, 69.23076923076923, 76.92307692307692, 100]
For convenience, here is Irritate's algorithm in a Java form. Add error checking, exception handling and tweak as necessary.
public class Algorithms {
public static double scale(final double valueIn, final double baseMin, final double baseMax, final double limitMin, final double limitMax) {
return ((limitMax - limitMin) * (valueIn - baseMin) / (baseMax - baseMin)) + limitMin;
}
}
Tester:
final double baseMin = 0.0;
final double baseMax = 360.0;
final double limitMin = 90.0;
final double limitMax = 270.0;
double valueIn = 0;
System.out.println(Algorithms.scale(valueIn, baseMin, baseMax, limitMin, limitMax));
valueIn = 360;
System.out.println(Algorithms.scale(valueIn, baseMin, baseMax, limitMin, limitMax));
valueIn = 180;
System.out.println(Algorithms.scale(valueIn, baseMin, baseMax, limitMin, limitMax));
90.0
270.0
180.0
Here's how I understand it:
What percent does x lie in a range
Let's assume you have a range from 0 to 100. Given an arbitrary number from that range, what "percent" from that range does it lie in? This should be pretty simple, 0 would be 0%, 50 would be 50% and 100 would be 100%.
Now, what if your range was 20 to 100? We cannot apply the same logic as above (divide by 100) because:
20 / 100
doesn't give us 0 (20 should be 0% now). This should be simple to fix, we just need to make the numerator 0 for the case of 20. We can do that by subtracting:
(20 - 20) / 100
However, this doesn't work for 100 anymore because:
(100 - 20) / 100
doesn't give us 100%. Again, we can fix this by subtracting from the denominator as well:
(100 - 20) / (100 - 20)
A more generalized equation for finding out what % x lies in a range would be:
(x - MIN) / (MAX - MIN)
Scale range to another range
Now that we know what percent a number lies in a range, we can apply it to map the number to another range. Let's go through an example.
old range = [200, 1000]
new range = [10, 20]
If we have a number in the old range, what would the number be in the new range? Let's say the number is 400. First, figure out what percent 400 is within the old range. We can apply our equation above.
(400 - 200) / (1000 - 200) = 0.25
So, 400 lies in 25% of the old range. We just need to figure out what number is 25% of the new range. Think about what 50% of [0, 20] is. It would be 10 right? How did you arrive at that answer? Well, we can just do:
20 * 0.5 = 10
But, what about from [10, 20]? We need to shift everything by 10 now. eg:
((20 - 10) * 0.5) + 10
a more generalized formula would be:
((MAX - MIN) * PERCENT) + MIN
To the original example of what 25% of [10, 20] is:
((20 - 10) * 0.25) + 10 = 12.5
So, 400 in the range [200, 1000] would map to 12.5 in the range [10, 20]
TLDR
To map x from old range to new range:
OLD PERCENT = (x - OLD MIN) / (OLD MAX - OLD MIN)
NEW X = ((NEW MAX - NEW MIN) * OLD PERCENT) + NEW MIN
I came across this solution but this does not really fit my need. So I digged a bit in the d3 source code. I personally would recommend to do it like d3.scale does.
So here you scale the domain to the range. The advantage is that you can flip signs to your target range. This is useful since the y axis on a computer screen goes top down so large values have a small y.
public class Rescale {
private final double range0,range1,domain0,domain1;
public Rescale(double domain0, double domain1, double range0, double range1) {
this.range0 = range0;
this.range1 = range1;
this.domain0 = domain0;
this.domain1 = domain1;
}
private double interpolate(double x) {
return range0 * (1 - x) + range1 * x;
}
private double uninterpolate(double x) {
double b = (domain1 - domain0) != 0 ? domain1 - domain0 : 1 / domain1;
return (x - domain0) / b;
}
public double rescale(double x) {
return interpolate(uninterpolate(x));
}
}
And here is the test where you can see what I mean
public class RescaleTest {
#Test
public void testRescale() {
Rescale r;
r = new Rescale(5,7,0,1);
Assert.assertTrue(r.rescale(5) == 0);
Assert.assertTrue(r.rescale(6) == 0.5);
Assert.assertTrue(r.rescale(7) == 1);
r = new Rescale(5,7,1,0);
Assert.assertTrue(r.rescale(5) == 1);
Assert.assertTrue(r.rescale(6) == 0.5);
Assert.assertTrue(r.rescale(7) == 0);
r = new Rescale(-3,3,0,1);
Assert.assertTrue(r.rescale(-3) == 0);
Assert.assertTrue(r.rescale(0) == 0.5);
Assert.assertTrue(r.rescale(3) == 1);
r = new Rescale(-3,3,-1,1);
Assert.assertTrue(r.rescale(-3) == -1);
Assert.assertTrue(r.rescale(0) == 0);
Assert.assertTrue(r.rescale(3) == 1);
}
}
I sometimes find a variation of this useful.
Wrapping the scale function in a class so that I do not need to pass around the min/max values if scaling the same ranges in several places
Adding two small checks that ensures that the result value stays within the expected range.
Example in JavaScript:
class Scaler {
constructor(inMin, inMax, outMin, outMax) {
this.inMin = inMin;
this.inMax = inMax;
this.outMin = outMin;
this.outMax = outMax;
}
scale(value) {
const result = (value - this.inMin) * (this.outMax - this.outMin) / (this.inMax - this.inMin) + this.outMin;
if (result < this.outMin) {
return this.outMin;
} else if (result > this.outMax) {
return this.outMax;
}
return result;
}
}
This example along with a function based version comes from the page https://writingjavascript.com/scaling-values-between-two-ranges
Based on Charles Clayton's response, I included some JSDoc, ES6 tweaks, and incorporated suggestions from the comments in the original response.
/**
* Returns a scaled number within its source bounds to the desired target bounds.
* #param {number} n - Unscaled number
* #param {number} tMin - Minimum (target) bound to scale to
* #param {number} tMax - Maximum (target) bound to scale to
* #param {number} sMin - Minimum (source) bound to scale from
* #param {number} sMax - Maximum (source) bound to scale from
* #returns {number} The scaled number within the target bounds.
*/
const scaleBetween = (n, tMin, tMax, sMin, sMax) => {
return (tMax - tMin) * (n - sMin) / (sMax - sMin) + tMin;
}
if (Array.prototype.scaleBetween === undefined) {
/**
* Returns a scaled array of numbers fit to the desired target bounds.
* #param {number} tMin - Minimum (target) bound to scale to
* #param {number} tMax - Maximum (target) bound to scale to
* #returns {number} The scaled array.
*/
Array.prototype.scaleBetween = function(tMin, tMax) {
if (arguments.length === 1 || tMax === undefined) {
tMax = tMin; tMin = 0;
}
let sMax = Math.max(...this), sMin = Math.min(...this);
if (sMax - sMin == 0) return this.map(num => (tMin + tMax) / 2);
return this.map(num => (tMax - tMin) * (num - sMin) / (sMax - sMin) + tMin);
}
}
// ================================================================
// Usage
// ================================================================
let nums = [10, 13, 25, 28, 43, 50], tMin = 0, tMax = 100,
sMin = Math.min(...nums), sMax = Math.max(...nums);
// Result: [ 0.0, 7.50, 37.50, 45.00, 82.50, 100.00 ]
console.log(nums.map(n => scaleBetween(n, tMin, tMax, sMin, sMax).toFixed(2)).join(', '));
// Result: [ 0, 30.769, 69.231, 76.923, 100 ]
console.log([-4, 0, 5, 6, 9].scaleBetween(0, 100).join(', '));
// Result: [ 50, 50, 50 ]
console.log([1, 1, 1].scaleBetween(0, 100).join(', '));
.as-console-wrapper { top: 0; max-height: 100% !important; }
I've taken Irritate's answer and refactored it so as to minimize the computational steps for subsequent computations by factoring it into the fewest constants. The motivation is to allow a scaler to be trained on one set of data, and then be run on new data (for an ML algo). In effect, it's much like SciKit's preprocessing MinMaxScaler for Python in usage.
Thus, x' = (b-a)(x-min)/(max-min) + a (where b!=a) becomes x' = x(b-a)/(max-min) + min(-b+a)/(max-min) + a which can be reduced to two constants in the form x' = x*Part1 + Part2.
Here's a C# implementation with two constructors: one to train, and one to reload a trained instance (e.g., to support persistence).
public class MinMaxColumnSpec
{
/// <summary>
/// To reduce repetitive computations, the min-max formula has been refactored so that the portions that remain constant are just computed once.
/// This transforms the forumula from
/// x' = (b-a)(x-min)/(max-min) + a
/// into x' = x(b-a)/(max-min) + min(-b+a)/(max-min) + a
/// which can be further factored into
/// x' = x*Part1 + Part2
/// </summary>
public readonly double Part1, Part2;
/// <summary>
/// Use this ctor to train a new scaler.
/// </summary>
public MinMaxColumnSpec(double[] columnValues, int newMin = 0, int newMax = 1)
{
if (newMax <= newMin)
throw new ArgumentOutOfRangeException("newMax", "newMax must be greater than newMin");
var oldMax = columnValues.Max();
var oldMin = columnValues.Min();
Part1 = (newMax - newMin) / (oldMax - oldMin);
Part2 = newMin + (oldMin * (newMin - newMax) / (oldMax - oldMin));
}
/// <summary>
/// Use this ctor for previously-trained scalers with known constants.
/// </summary>
public MinMaxColumnSpec(double part1, double part2)
{
Part1 = part1;
Part2 = part2;
}
public double Scale(double x) => (x * Part1) + Part2;
}

Resources