Solving equations: is it an error in the formula or an inaccuracy in numerical integration calculations?

According to the code / calculations below, it seems that you only need higher values ​​to MaxRecursion. Then only slow convergence messages are given ("NIntegrate :: slwcon").

a = 7; m = 5; n = 1;
Print("nEquation: z^", m, " - ", a, "*z^", n, " - 1 = 0n");
Print("Ordinary solution:");
NSolve((z^m - a z^n - 1))
sol = z /. NSolve((z^m - a z^n - 1))

(* During evaluation of In(88):= 
Equation: z^5 - 7*z^1 - 1 = 0

During evaluation of In(88):= Ordinary solution: *)

(* {{z -> -1.58871}, {z -> -0.142866}, {z -> 
   0.0355442 - 1.62852 I}, {z -> 0.0355442 + 1.62852 I}, {z -> 

{-1.58871, -0.142866, 0.0355442 - 1.62852 I, 
 0.0355442 + 1.62852 I, 1.66049} *)

Print("Solution with definite integration:"); S = 
Table(Exp(2 j Pi I/m) + 
   1/(2 Pi I) (Exp((2 j + 1) Pi I/m)*
        Log(1 + a t^n/(1 + t^m) Exp((2 j + 1) Pi I n/m)), {t, 0, 
         Infinity}, MaxRecursion -> 200) - 
      Exp((2 j - 1) Pi I/m)*
        Log(1 + a t^n/(1 + t^m) Exp((2 j - 1) Pi I n/m)), {t, 0, 
         Infinity}, MaxRecursion -> 200)), {j, 0, m - 1});

During evaluation of In(93):= Solution with definite integration:

During evaluation of In(93):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(93):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small. *)


(* {1.66049 + 0. I, 
     0.0355442 + 1.62852 I, -1.58871 + 7.8*10^-8 I, -0.142866 - 
     7.8*10^-8 I, 0.0355442 - 1.62852 I} *)

Here we see that you have all the values ​​in your "ordinary solution" (using a certain tolerance):

Complement(S, sol, 
 SameTest -> (Abs(#1 - #2)/Norm({#1, #2}, Infinity) < 10^-6 &))

(* {} *)

javascript – If I want to create a site that delivers calculations, should I calculate the calculations in the browser or on the server?

I already wrote the code in python with tkinter and sqlite.
I am learning html, css and javascripts.

As I intend to create a site that offers the same, I have the doubt how to start, make the code in javascripts? But if so, it will run in the browser and my code will be exposed to plagiarism … And if I do it on the server, the calculation would take much longer? I would also have the risk that if users increase, can the site collapse?

Any advice … thank you very much …

Mining theory: how many hash calculations are needed to reach a BTC?

The double SHA 256 follows a uniform distribution that means that all hashes have the same probability of occurring. Therefore, your chances of finding the block header hash that is less than the goal is the same for each round of hashing.

With the current mining difficulty of 10183488432890, the target bits are 0x171ba3d1. This means that you will need to find the block header hash that is less than or equal to 0x0000000000000000001ba3d10000000000000000000000000000000000000000. For a double hash round that is a probability of 2,28631×10-2. 3. Call it P. So, the probability of not finding a valid hash is (1-P). For N hash attempts, the probability of not finding the valid hash is (1-P)north. To make sure you find a block, we must make sure that (1-P)^N -> 0. As P -> 0, (1-P)^N = 1-N*P (using the Taylor expansion). Solving both equations you get N = 1 / P = 4.3738×1022

At your hash rate of 1 TH / s, it will take you 4.3738×1010 seconds that is 1386.91 years.

Mining theory: are the profitability calculations of mining builders / sellers true?

Regarding this question here, how many hash calculations are needed to reach a BTC? , it takes about 1387 years with a power rate of 1 TH / s to reach 1 BTC.

So, if someone has a machine with a power rate of 53TH / s and his machine runs 24 hours a day, 7 days a week, he can reach 1 BTC in 1387/53 = 26.1 years, and if he has 100 of that machine, You can earn 1 BTC in 95.5 days, or almost 4 BTC per year.

So, if the price of 1 BTC is about $ 9500 today, you earn 9500 * 4 = $ 38,000 per year (let's think electricity consumption is free!). But on many websites like this, it calculated the profitability of the same machine for $ 4,333 per year and will be $ 433,000 per year for 100 machines! (He also considered the consumption of electrical energy).

How is it possible?

Are Google Play storage space calculations inaccurate?

Why exactly does this "More storage space" message appear when an application is installed through the Google Play store, even when there is enough space, theoretically available (more x MB needed)? And, in addition to that, after deleting one or more applications, this message continues to appear, wanting additional space. Interestingly, sometimes x becomes taller than it was before removing some applications. Only when I delete very large applications, the store continues with the installation. Is it because Play Store reserves part of the storage space for itself, which is not available for anything else?

java – Backtracking – optimizing my code to eliminate some unnecessary calculations

I solved the following problem using tracking:

They give us a list of military units, their weight and their
(numerical) force. We have several boats with a limit
Loading capacity. Determine how to load ships with military units, then
that the load capacity of each ship is not superior and that we have
the maximum possible military force in our ships

However, my code is not fast enough, since many unnecessary calculations are being made, which do not lead to an adequate solution. How would you optimize my code? My idea is to use memorization, but how would you implement it? Thanks for any help!

I tried to comment on my code and refactor my code the best I could.

public class HeroesOntTheBoat {

private int() arrayWithGeneratedNumbers;
private int numberOfShips;
private int max;
private int() bestArray;
private ArrayList strengths;
private ArrayList weights;
private ArrayList carryingCapacities;

public HeroesOntTheBoat() {
    carryingCapacities = new ArrayList(); // create arraylist for the carrying capacities of ships
    strengths = new ArrayList(); //create arraylists for strengths and weights of units
    weights = new ArrayList(); //create arraylists for weights
    max = 0; // global variable max for finding the best strength

private void generate(int fromIndex) { // I generate all combinations between 0 and numberOfShips
    if (fromIndex == arrayWithGeneratedNumbers.length) { // 0 is representing that unit is being left behind
        processGeneratedNumbers();      // 1,2,3,4..n are representing the number of ship that the unit is loaded on
        return;                         // index of a number in array is representing a specific unit               

    for (int i = 0; i <= numberOfShips; i++) {
        arrayWithGeneratedNumbers(fromIndex) = i;
        generate(fromIndex + 1);

public void input(String input) {
    Scanner sc = null;
    try {
        sc = new Scanner(new File(input)); // load my input from a textfile
        numberOfShips = sc.nextInt();  // load the number of ships
        for (int i = 0; i < numberOfShips; i++) { //add carrying capacities to arraylist
        bestArray = new int(weights.size()); // array where we will remember the best combination of units
        while (sc.hasNext()) {
        arrayWithGeneratedNumbers = new int(weights.size()); // array where we will generate numbers
        generate(0); // run the generation
        System.out.println(Arrays.toString(bestArray) + " this is the best layout of units"); // after the generation is over
        System.out.println(max + " this is the max strength we can achieve"); // print the results
    } catch (FileNotFoundException e) {
    } finally {
        if (sc != null) {

public void processGeneratedNumbers() {
    int currentStrength = 0; // process every generated result
    boolean carryingCapacityWasExceeded = false;
    int() currentWeight = new int(numberOfShips + 1);
    for (int i = 0; i < arrayWithGeneratedNumbers.length; i++) { // calculate weights for every ship and ground
        currentWeight(arrayWithGeneratedNumbers(i)) += weights.get(i);
    for (int i = 0; i < currentWeight.length; i++) { // is capacity exceeded?
        if (i != 0 && currentWeight(i) > carryingCapacities.get(i - 1)) { // ignore 0, because 0 represents ground(units I left behind)
            carryingCapacityWasExceeded = true;
    if (carryingCapacityWasExceeded == false) { // if capacity isn't exceeded
        for (int i = 0; i < arrayWithGeneratedNumbers.length; i++) { // calculate strength
            if (arrayWithGeneratedNumbers(i) != 0) { // ignore 0, because I left units with 0 behind on the ground
                currentStrength += strengths.get(i);
        if (currentStrength > max) { // is my current strength better than global maximum?
            max = currentStrength; // replace my global maximum
            bestArray = arrayWithGeneratedNumbers.clone(); // remember the new best layout of units



public static void main(String() args) {
    HeroesOnTheBoat g = new HeroesOnTheBoat();

Sample Entry:

2 60 40
30 400
20 500
50 100
40 100
30 50
60 75
40 20

Differential geometry: detailed calculations of the geodetic equation (using Langrangian or not)

Given a multiple and one way $ gamma $ In this multiple, I want to know if this path is really geodesic.

From what I read, I should calculate the geodetic equation with that route, then check if it is equal to zero. Therefore, you should calculate:

$ {d ^ 2 x ^ mu over ds ^ 2} + Gamma ^ mu {} _ { alpha beta} {d x ^ alpha over ds} {d x ^ beta over ds} $

Where, if I understand correctly, $ s $ it is the variable that parameterizes $ gamma $Y $ x ^ mu $ are the components of $ gamma $ in some generalized coordinate system.

Even understanding Christoffel's symbols is really difficult for me, and I may not be ready to use them yet.

I read that there is another formulation (probably simpler) that uses a Lagrangian, which I would need to calculate, if I'm right:

$ frac { partial dot { gamma}} { partial x ^ mu}
– frac { mathrm d} { mathrm ds} left ( frac { partial dot { gamma}} { partial dot {x} ^ mu} right) $

Again, I am failing to manipulate such expressions.

I would like you to help me with this simple example: in $ mathbb {R} ^ 3 $, let the manifold be the radio sphere $ 1 $ and center $ Or $ and consider:

$ gamma: s mapsto begin {pmatrix} cos s \ sin s \ 0 end {pmatrix} $

Obviously, this parametrizes a large circle of the sphere and, therefore, is a geodesic. So I know that our calculations should give us $ 0 $, still and I don't get it. We assume that we have Euclidean metric.

Computing $ dot { gamma}: s mapsto begin {pmatrix} – sin s \ cos s \ 0 end {pmatrix} $ It is not what poses a problem.

To my knowledge, we have $ x ^ 1 = cos s $So what does he do $ frac { partial (- sin s)} { cos s} $ value ? Does it mean I should express $ – { sin s} $ since $ cos s $, which would give something like $ – { sin s} = pm sqrt {1 – ( cos s) ^ 2} $ ?

Some tips about me:

  • I understand Einstein's sum convention;
  • You should be familiar with Leibniz differential notations, although detailing the steps does not hurt;
  • I have been initiated with tensioners, but I cannot pretend to dominate them;
  • I know a differential vector operator, but I would rather avoid using nabla notation;
  • I know that the Lagrangian is somehow a "potential" that we want to minimize, but I have no intuition about it.

Thanks for your attention.

How to wait for Google spreadsheet calculations to be updated before retrieving data from the cell in the Apps Script web application?

I am creating a Google Apps Script web application that uses Google Sheets as a backend. This web application basically allows users to keep track of their work time (clock for the day, clock for lunch, clock for lunch and clock for the day). Currently, I have the application that reads spreadsheet data and displays it in an HTML table using a JavaScript call from the client side to the server side javascript, which is what really opens the SpreadsheetApp (by URL) and retrieves the data to send to the client javascript lateral for visualization. However, the spreadsheet has quite a few calculations that must be done and it takes a few seconds before updating the values. My script, however, reads the initial values ​​and does not wait for them to update; often leads to the display of obsolete data I tried to use SpreadsheetApp.flush() to force the spreadsheet to finish calculating before recovering the data in my script, however, it still seems to extract the data before the calculations are finished. I should be using SpreadsheetApp.flush() before or after opening the spreadsheet with SpreadsheetApp.openByUrl(spreadsheetURL)? Or maybe after my call to userSpreadsheet.getSheetByName("Timecard")? I tried each one, but it was in vain.

Any help is appreciated!

trace – Why are centroid calculations with integral line incorrect?

all the world. I am currently trying to calculate the centroids of objects using parametric and integral line equations. enter the description of the image here

I already have a program that can parameterize any shape accurately with a closed curve. I also have the two integrals configured to calculate the centroids. Here is the code I am working with.

param(x_, m_, t_) := 
Module({f, n = Length(x), nf}, 
f = Chop(Fourier(x))((;; Ceiling(Length(x)/2)));
nf = Length(f);
 2 Abs(f)/Sqrt(n) Sin(
   Pi/2 - Arg(f) + 2. Pi Range(0, nf - 1) t), .01)((;; 
 Min(m, nf)))))

tocurve(Line(data_), m_, t_) := param(#, m, t) & /@ Transpose(data)
img=Import("Coronal Holes.jpg")
img = Binarize(img~ColorConvert~"Grayscale");
lines = Cases(
 Contours -> {0.5}), _Line, -1);

Evaluate(tocurve(#, 100000000, t) & /@ lines), {t, 0, 1}, 
Frame -> True, Axes -> False, ImageSize -> Large)
ParametricEquations = Evaluate(tocurve(#, 100000000, t) & /@ lines)
n = Length(ParametricEquations)
img2 = Binarize(img~ColorConvert~"Grayscale");

bsFs = Cases(
Normal@ListContourPlot(Reverse@ImageData(img2), Contours -> {0.5}),
Line(x_) :> BSplineFunction(x), All);

ParametricPlot(Evaluate(Through@bsFs@t), {t, 0, 1}, Frame -> True, 
 Axes -> False, ImageSize -> Large, Axes -> false, Frame -> True)
stepsize = 0.0001
list = Table(
N(Evaluate(Through@bsFs@t) /. t -> i), {t, 0, 1, stepsize})
xmatrix = 
Table(Table(list((i, j, 1)), {i, 1, (1/stepsize) + 1}), {j, 1, n})
ymatrix = 
Table(Table(list((i, j, 2)), {i, 1, (1/stepsize) + 1}), {j, 1, n})
Minx = Table(xmatrix((i, Ordering(xmatrix((i)), 1))), {i, 1, n})
Miny = Table(ymatrix((i, Ordering(ymatrix((i)), 1))), {i, 1, n})
x = Table(ParametricEquations((i, 1)), {i, 1, n})
y = Table(ParametricEquations((i, 2)), {i, 1, n})
Mx = Table(NMinValue({x((i)), 0 <= t <= 1}, t), {i, 1, n})
My = Table(NMinValue({y((i)), 0 <= t <= 1}, t), {i, 1, n})
NewParametricEquations = 
Table({x((i)) - (Mx((i)) - Minx((i))), 
y((i)) - (My((i)) - Miny((i)))}, {i, 1, n})
ParametricPlot(NewParametricEquations, {t, 0, 1}, ImageSize -> Large, 
Axes -> False, Frame -> True)
xCentroids = 
NewParametricEquations((i, 1))^2*
 D(NewParametricEquations((i, 2)), t), {t, 0, 1})/
2*NewParametricEquations((i, 1))*
 D(NewParametricEquations((i, 2)), t), {t, 0, 1}), {i, 1, n})
yCentroids = 
Table(NIntegrate(-NewParametricEquations((i, 2))^2*
 D(NewParametricEquations((i, 1)), t), {t, 0, 1})/
NIntegrate(-2*NewParametricEquations((i, 2))*
 D(NewParametricEquations((i, 1)), t), {t, 0, 1}), {i, 1, n})
Centroids = Table({xCentroids((i)), yCentroids((i))}, {i, 1, n})

The only problem is that integrals do not always give precise or reasonable answers to the centroid coordinates in certain ways. Most of the time they work, but I would like them to work all the time if possible.

I think the purpose of some of my codes can be confusing, so if you want an in-depth explanation you can consult this publication.

Why are the coordinates of the parametric diagram different from the image?

Basically, my previous problem was that the coordinates of the parametric graphics were not the same as the pixel coordinates in the original image. This was a problem because even if I calculated the centroids correctly for the plotting, it would still be off for the image and, therefore, would be a useless answer. Someone was kind enough to give an alternative method, but unfortunately I could not recover the functions and integrate it. So I ended up using his method to make horizontal and vertical changes in my original equations. It is probably not the most efficient way to solve my coordinate problem, but I am new to Mathematica and it was the best I could find.

dnd 5e – Understanding CR calculations

I have been working on a tool to help me design monsters, specifically doing CR calculations as described in the DMG. To prove it, I've tried it on some monsters in the Monster manual, which of course are giving me different results.

I just want to say in advance that I am fully aware that the DMG method does not align with what is actually in the MM, and that a different calculation was used for it. And for my purposes it's fine, but it makes the test quite difficult. I also understand that the game tests can influence the CR.

So, what I want to verify is: for these 3 test monsters, is my calculation correct or has something missed me? And if it is correct, is there a widely accepted or documented reason for these monsters specifically have different RCs?

Wolf (MM CR: 1/4, calculated CR: 1/2)

HP: 11
AC: 13
Damage per round: 7
Attack bonus: 4 + 1 (for Pack Tactics) = 5

Defensive CR: 1/8
Offensive CR: 1
Average CR: 0.625 rounded = 1/2

Wight (MM CR: 3, calculated CR: 2)

HP: 45 x 2 (for damage resistors) = 90
CA: 14
Damage per round: 2 x 6 (long sword) = 12
Attack bonus: 4

Defensive CR: 2
Offensive CR: 1
Average CR: 1.5 rounded = 2

Planetar (MM CR: 16, calculated CR: 15)

HP: 200 x 1.25 (for damage resistors) = 250
CA: 19 + 2 (magic resistance) + 2 (3 saving shots) = 23
Damage per round: 2 x 43 (great angelic sword) = 86
Attack bonus: 12

Defensive CR: 12 + 3 (adjust by AC) = 15
Offensive CR: 13 + 2 (adjust per attack) = 15
Average CR: 15