## c – Calculating the position in the Pololu reflectance matrix produces unexpected results

I am playing with analog inputs using an ATmega328p (DFRobot Romeo board) and a Pololu reflectance matrix of 8 sensors.

I can read my raw data values, invert them and display them in a terminal emulator, and I can see that the values ​​change when I hold a white card over them. The value varies (ideally) from 0 to 1000 (where 1000 represents the card that is almost in front of the sensor).

When I execute this code:

``````while(1)
{
//get the raw values from the ADC for each channel
for(uint8_t channel = 0; channel < 8; channel++)
{
raw_values(channel) = analog(channel);

//invert the raw value
raw_values(channel) = DIVISOR - raw_values(channel);
}

//have any values changed from the previous scan?
//if so, set changed
for(uint8_t channel = 0; channel < 8; channel++)
{
if(raw_values(channel) != previous_values(channel))
{
changed = 1;
}

//copy current to previous
previous_values(channel) = raw_values(channel);
}

//if any values changed, do your math and print the results
if(changed)
{
for(uint8_t channel = 0; channel < 8; channel++)
{
//print the channel#
transmitString(channelString);
printDec16bit(channel);
transmitString(space);

//print the raw value from the ADC conversion
printDec16bit(raw_values(channel));
transmitString(raw);
transmitString(space);

//calculate the position value at each sensor
transmitString(positionString);
positions(channel) = (uint16_t)((POSITION_REF/DIVISOR) * raw_values(channel));
printDec16bit(positions(channel));
printCR();
}

printCR();

//clear changed flag
changed = 0;
}

//provide 1 second delay
delay_ms(2000);
}
``````

I get this output in my emulator:

This is expected.

However ... The task I need to accomplish is that I should have a number that represents my position on the matrix as I move from one sensor to another. Ideally, the number should be a continuous number between 1000 and 8000, where sensor 1 is position 1000, sensor 2 is position 2000, sensor 3 is position 3000, etc. The formula I am using to calculate this is:

𝑝𝑜𝑠𝑖𝑡𝑖𝑜𝑛 = 1000 · 𝑉𝑎𝑙0 + 2000 · 𝑉𝑎𝑙1 + ⋯ + 8000 · 𝑉𝑎𝑙8 𝑉𝑎𝑙0 + 𝑉𝑎𝑙1 + ⋯ + 𝑉𝑎𝑙8 / 𝑉𝑎𝑙0 + 𝑉𝑎𝑙1 + ⋯ + 𝑉𝑎𝑙8

To calculate this, I created the following function call.

``````uint16_t calculatePosition(uint16_t * channel_positions)
{
uint32_t intermediates(8);
uint32_t temp_sum = 0;
uint16_t divisor = 0;
uint16_t value = 0;

for(uint8_t i = 0; i < 8; i++)
{
intermediates(i) = channel_positions(i) * ((i + 1) * 1000);
}

for(uint8_t j = 0; j < 8; j++)
{
temp_sum = temp_sum + intermediates(j);
}

for(uint8_t k = 0; k < 8; k++)
{
divisor = divisor + channel_positions(k);
}

value = temp_sum/divisor;

return value;
}
``````

When I call this function and print the result, I not only get a garbage response, the values ​​printed before are also messy.

Here is the modified while loop ...

``````while(1)
{
//get the raw values from the ADC for each channel
for(uint8_t channel = 0; channel < 8; channel++)
{
raw_values(channel) = analog(channel);

//invert the raw value
raw_values(channel) = DIVISOR - raw_values(channel);
}

//have any values changed from the previous scan?
//if so, set changed
for(uint8_t channel = 0; channel < 8; channel++)
{
if(raw_values(channel) != previous_values(channel))
{
changed = 1;
}

//copy current to previous
previous_values(channel) = raw_values(channel);
}

//if any values changed, do your math and print the results
if(changed)
{
for(uint8_t channel = 0; channel < 8; channel++)
{
//print the channel#
transmitString(channelString);
printDec16bit(channel);
transmitString(space);

//print the raw value from the ADC conversion
printDec16bit(raw_values(channel));
transmitString(raw);
transmitString(space);

//calculate the position value at each sensor
transmitString(positionString);
positions(channel) = (uint16_t)((POSITION_REF/DIVISOR) * raw_values(channel));
printDec16bit(positions(channel));
printCR();
}

printCR();

//calculate and display 'position'
position = calculatePosition(positions);
printDec16bit(position);
printCR();
printCR();

//clear changed flag
changed = 0;
}

//provide 1 second delay
delay_ms(2000);
}
``````

And here is the garbage that I get as an exit. An incorrect position value and a messy UART output.

Could anyone offer an explanation for this?

## exponential function: avoid arithmetic overflow when calculating LambertW (exp (x))

In physics, I must calculate W (exp (x)), and x is greater than 10 ^ 5. When I calculate it with Wolfram I get a number less than x, but when I try to program it in c ++ or python, I leave the range of error.
How can I convert this formula, so I don't need to calculate exp (x)?

## usability study: when calculating PSSUQ scores, what happens to the NA responses?

PSSUQ (Post-study system usability questionnaire) is a post-task measurement tool used to evaluate the usability of the system. The current third version has 16 statements. Each statement has a likert scale from 1 (strongly agree) to 7 (strongly disagree). Each statement also has the NA option (not applicable).

PSSUQ has a general score that is calculated by averaging the scores given to the statements.

The user fully agrees with each statement, therefore, the overall PSSUQ score is 1.

PSSUQ also has subscales for system utility (SysUse), information quality (InfoQual) and interface quality (IntQual). Your scores are calculated as:

• SysUse: average scores of statements 1 to 6
• InfoQual: average scores of declarations 7 to 12
• IntQual: average scores of declarations 13 to 15.

But how should I handle the statements that the user thinks are not applicable? Do they get the value 0 or just ignore them from the calculation? For example, in IntQual it has only three declarations if NA obtains the value 0:

The user fully agrees with two statements and one does not apply, the IntQual score is 0.667.

The user fully agrees with two statements and one does not apply, the IntQual score is 1.

## sql server – Error calculating formula based on an SQL function

I want to add a function that calculates Euler's number based on a factorial in SQL, but I don't know if I am doing my programming well based on the function that I have declared.
The number you should throw me is the 2,71828

I will leave my code waiting for your help. THANK YOU

/Factorial/

``````alter function factorial(@num float(5))
returns float
begin
declare @fact float
if @num = 0 or @num = 1
select @fact = 1
else
select @fact = dbo.factorial(@num -1) * @num
return @fact
endselect (dbo).factorial (20)
``````

/euler/

``````alter function euler (@e float(10))
returns float
begin
declare @i float=1, @sum float=0
while(@i <= @e)
begin
set @sum  =1+(1/(select (dbo).factorial (@i)))
set @i=@i+1
end
return @sum
end
select (dbo).euler (3)
``````

## Complexity of time: What is the most efficient algorithm for calculating polynomial coefficients from its roots?

Dice $$n$$ estate $$x_1, x_2, dotsc, x_n$$, the corresponding monic polynomial is $$y = (x-x_1) (x-x_2) dotsm (x-x_n) = prod_ {i} ^ n (x – x_i)$$. To obtain the coefficients (ie $$y = sum_ {i} ^ n a_i x ^ i$$), a direct expansion requires $$O (n ^ 2)$$ Steps.

Alternatively yes $$x_1, x_2, dotsc, x_n$$ are different from each other The problem is equivalent to polynomial interpolation with $$n$$ points: $$(x_1, 0), (x_2, 0), dotsc, (x_n, 0)$$. The fast polynomial interpolation algorithm can be executed in $$O (n log ^ 2 (n))$$ hour.

I want to ask if there is a more efficient algorithm better than $$O (n ^ 2)$$? Even if there are duplicate values ​​between $${x_i }$$? If it helps, we can assume that the polynomial is over some primary finite field, that is. $$x_i in mathbf {F} _q$$.

## ti84 plus ce calculating values ​​in a grpah

I have had my calculator for a year or two and in recent months the `2nd` `trace` `1:value` The function for the graph in my calculator will not show the value of y when I enter a number.

## or operational algebras or – Norms for calculating operator polynomials in the Hilbert space and generalized inequality of von Neumann

Leave $$T$$ be an operator $$l ^ 2 ({ mathbb {Z} _ { geq 0}}) a l ^ 2 ({ mathbb {Z} _ { geq 0}})$$, $$e_n mapsto sqrt {1 – q ^ {2 (n + 1)}} e_ {n + 1}$$, where $$0 . I want to compute $$| f (T, T *) |$$ (operator standard) for any $$f in mathbb {C} (z, bar z)$$. Operator $$T *$$, of course, is Hilbert's conjugate and $$T ^ * e_0 = 0$$, $$T ^ {*} e_n = sqrt {1-q ^ {2n}} e_ {n-1}$$ for $$n> 0$$.

I'm not sure if that calculation is possible and would be happy to show that $$| f (T, T *) | to sup limits_ {| z | leq 1} f (z, bar z)$$ how $$q$$ It goes to 1 because it's really why I need to calculate the rules first.

I think there is a generalization of von Neumann's inequality as $$q$$-analysis or something (there are many generalizations) because the usual inequality proves it for polynomials $$g in mathbb {C} (z)$$ (without $$bar z$$)

Question: Does anyone know any useful facts or inequalities related to my question? Something that could help.

## Error calculating the rest of the division

I am studying and establishing programs.
There is a part that I put

``````     if litro % 3.6 == 0:
``````

And when `litro=36`, the result does not have to be `true`?
Yes `36/3.6=10` And there is nothing left.

But when I put this in the program, the value is `3.59999999....`
When I put

``````     55%5.5 == 0
``````

the result is `true`.

I want to know why `55%5.5` stay `0` Y `36%3.6` no …

## Worksheet function: Excel formula for calculating the date based on 2 cells and how to copy to other cells? Help a newbie please

Novice Excel user here. Here is a simplified version of my spreadsheet:

start date end date eday duration
-21 4
12 0

begindate = "03/03/2020"

I want to create formulas to calculate the start date and the end date based on the values ​​in the eday columns and duration and start date:

start date = start date + day
end date = start date + duration

So, for the previous example, if I apply a formula, I would expect the following result:

start date end date eday duration
11/02/2020 02/11/2020 -21 4
03/15/2020 03/19/2020 12 0

begindate "03/03/2020" will always be the same.

I could make a formula work, but when I use the fill controller it doesn't copy the formula correctly.

Help a newbie with these questions:

(1) Where is the best place to store the start date "03/03/2020" – a separate worksheet? encode it? other?

(2) What is the formula for the start date and the end date?

(3) How do I copy the formula in all rows of the column?

Thank you.

## JavaScript: calculating the complexity of the algorithm's time

I will begin by saying that, according to my understanding of the Code Review, this question is fine, since you are using a work code.

I am trying to calculate the time complexity of an algorithm using `n` in the code below.

I have a working solution for an encoding challenge to sort a stack using just another stack, and I have added a counter variable `n` which increases in any place where an element of the battery is pushed, busted or retained.

Code:

``````const sortStack = (stack) => {
let n = 0;
sorted = new Stack();
while (stack.storage.length) {
tmp = stack.pop();
n += 1;
if (tmp >= sorted.peek()) {
sorted.push(tmp);
n += 1;
} else {
while (tmp < sorted.peek()) {
stack.push(sorted.pop());
n += 1;
}
sorted.push(tmp);
n += 1;
}
}
console.log("n: ", n);
return sorted;
}

sortedStack = sortStack(s);
sortedStack.printContents();
``````

If my calculations and use of `n` are correct, then this algorithm has an input `n` of 6 (length of `stack`) with a final `n` of 30, which would give a time complexity of O (N * 5).

Is this correct?