Divide by zero error using Sigma notation - mathcad

I am trying to do a a sigma operation on this but MathCad gives this strange error. How can I go past this or replace the position by 0? Thanks
I have tried a for loop but does not work.

Related

How to find the minimun multiple given an incomplete number without using brute force

I just want a direction in this programming problem from an online judge (URI online judge - 2699).
Given two numbers, S and N, S is incomplete, so S can be given in the form ?294?? where the first digit is not zero, I need to find the minimum number that has the same digits as S and is multiple of N. If is not possible, then you just return a *. S can have up to 1000 digits and N < 1000.
I will describe my attempts:
Brute Force: I try every combination of numbers and get the first one to be multiple of N. Finding a solution when it exists is not the problem at all, but discovering that does not exist a solution when S is big can be really problematic and take infinite time.
Brute Force but optimizing the form of finding the rest: This attempt i save into an array the rest of the division for the digit 1 in the i position, so for i = 3, in v[3] i will have 1000%N. Knowing that (AB) MOD N = ((A MOD N)B) MOD N it's possible to write an array pretty quick and optimize the way i calculate the Mod of S which. This attempt does improve the time but is a Brute Force Attempt and has the same issues that the previous one.
Using the remainder to do the recursion: Ex: If i have the number
?294?? in S, i get the remainder of 29400 and calculate how much is needed to have a multiple (N - rem), then i try to get it all from the first digit, if it is not possible then i decrease how much I want and try again, then I go to the left and try with another number. Ex if i need 7 to reach N and can get 5 with the first digit, then I will try to find 2 within the second digit and so on.
Does it have a concept that i ain't seeing here ? I'm trying this problem for almost 3 days, searching ways to do this and not getting anywhere because of time.
EDIT: Thanks for the comments, after thinking all day about this problem and reading a lot of Dynamic Programming I could figure a way to apply DP in this problem, I won't say exactly how but the key is to understand DP and figure a way to reduce the size of your problem.

How to take the exponent of math/big.Float in Go?

I couldn't find anything in the API. Converting the number to a math/big.Int and back is not an option because the fractional component is significant to my calculation.
I'll end up repeatedly multiplying if there's no API, but that's a dissatisfying solution (math/big.Int.Exp is just O(log(n))) which might not be practical when I run into this problem again.
Thanks!
You may use MantExp() to take the exponent of a big.Float for a particular base/mantissa. Note that the formula for calculating the exponent for a given mantissa is:
x == mant × 2**exp

Find first digit of 2^n where n is of order 10^5

Today while going through a random video on youtube, I learn't about a very interesting law called Benford's law. I was wondering if it is possible to write a code to verify it for a^n.
I want to write a code that prints the first digit of 2^n where n is of order 10^5. Is it possible to write a code for it?
I know I haven't posted any code sample or shown any research effort.I am unable to think of any algorithm for it.
Use logarithms.
log_10(2) = 0.30102999566
log_10(2^100000) = 30102.999566
In other words, 2^100000 is a 30103-digit number, whose first digit can be found from the fractional part of this number:
10^0.999566 = 9.9900..

Equivalent "chop" function in Maple

The Chop feature in Mathematica replaces approximate real numbers in expression that are close to zero by the exact integer. I am searching for an equivalent function in Maple. Kindly note that I am NOT in search of trunc, round, frac etc. as they round off other floats to integers. I am only interested in "chopping" or rounding the near to 0 numbers to 0.
Any help is highly appreciated!
Check out Maple's command fnormal.

Initial guess for Newton Raphson

How can I determine the initial guess of the equation Ax+Bsin(x)=C in terms of A,B and C ?
I am trying to solve it using Newton Raphson. A,B and C will be given during runtime.
Is there any other method more efficient than Newton Raphson for this purpose ?
The optimal initial guess is the root itself, so finding an "optimal" guess isn't really valid.
Any guess will give you a valid solution eventually as long as f'(x0) != 0 for any step, which only occurs at the zeroes of cos(x), which are k*pi + pi/2 for any integer k.
I would try x0 = C * pi, just to see if it works.
Your biggest problem, however, would be the periodic nature of your function. Newton's method will be slow (if it even works) for your function as sin(x) will shift x0 back and forth over and over.
Precaution:
In Newton's method, do you notice how f'(xn) is in the denominator? f'(x) approaches 0 infinitely many times. If your f'(x) = 0.0001 (or anywhere close to zero, which has a chance of happening), your xn+1 gets thrown really far away from xn.
Worse yet, this can happen over and over due to f'(x) being a periodic function, which means that Newton's method might never even converge for an arbitrary x0.
The simplest "good" approximation is to just assume that sin(x) is approximately zero, and so set:
x0 = C/A
Well, if A,B and C are real and different from 0, then (B+C)/A is an upper quote to the highest root and (C-B)/A is a lower quote to the lowest root, as -1 <= sin(x) <= 1. You could start with those.
Newton method can work with any guess. the problem is simple,
if there is an equation and I guessed x0=100
and the best close solution for it is x0=2
and I know the answer is 2.34*
by using any guess in the world you will eventually get to 2.34*
the method says to choose a guess because without a valid guess it will take many solutions which aren't comfortable no one wants to repeat the method 20 times
and guessing a solution is not hard
you just find a critical point-
for example, 3 is too big and 2 is too small
so the answer is between 2 and 3
but if instead guessing 2 you guess 50
you will still get to the right solution.
like I said it will just take you much longer
I tested the method by myself
I guessed 1000 to a random equation
and I knew the best guess was 4
the answer was between 4 and 5
I chose 1000 it took me much time
but after a few hours, I got down from 1000 to 4.something
if you somehow can't find a critical point you can actually put a random number equals to x0 and then eventually you will get to the right solution
no matter what number you guessed.

Resources