Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [programming]

For mathematical questions related to programming, and questions where a computer-aided solution is strongly suggested. A strong connection with a mathematical topic is needed to make programming questions on-topic. This should not be the only tag. Consider also using the tags (algorithms), (numerical-methods), or (linear-programming).

1
vote
1answer
24 views

How to compute acute triangles and their values from sections of a circle?

I am working with a sensor that outputs data in forms of radial beams. In order for it to be useful for my application I have to compute a value of one side of the acute triangles that can be seen in ...
0
votes
0answers
20 views

loop over a file keeping the number of calculations constant

I have the following task: I have a file with 1.6e6 lines (only one floating point number per line), that I need to perform some calculation between each element, ...
0
votes
1answer
38 views

Sidestepping Factorial Calculations?

Please forgive me if I ramble or use weird terms to try and describe what I’m after; I’m a programmer not a mathematician. The scenario: A large number of players, playing a real-time game in 3d ...
0
votes
0answers
35 views

Greatest Common Divisor - Programming Question

You are given a number $g$. Find a sequence $A$ of length $n$ which satisfies the following condition: $GCD ( A_0, A_1, A_2, .... ,A_i, ..... ,A_{n-1} ) = g.$ $A_i > g, \ 0 \le i < n.$ $A_i \...
0
votes
1answer
33 views

How do I calculate the number of pairs/quadruples in an array such that their sum is divisible by '3'?

How do I calculate the number of pairs/quadruples in an array such that their sum is divisible by '3' ? I know the brute force approach, I am looking for a much optimized solution :-) I have solved ...
0
votes
0answers
6 views

HELP with SAS DATA programs [on hold]

I need help writing a SAS program that does the following in order. Write a SAS program to do the following in order: Create a SAS library, mylib that connects to the folder U:\STA575\Exam1. You ...
0
votes
0answers
21 views

equal-if (jbob proof assistant)

I'm trying to read through The Little Prover and the book introduces a language, ACL2, a Common Lisp derivative, for talking about proofs about programming languages. The book introduces the ...
-1
votes
0answers
20 views

How to numerically compute the partial derivatives of a vector of user-defined functions in MATLAB?

I have a self-written MATLAB function, say myfun(b0,b1), which takes two parameters as the input and returns a 1x6 vector of output, say [m1, m2, m3, m4, m5, m6], all of which of course depend on (b0,...
0
votes
0answers
11 views

How to create a convex polygon which is the superset of a given polygon?

I have a JTS_footprint like this, POLYGON ((46.542770 -65.500984,54.130459 -63.660416,59.213402 -66.664993,51.004562 -68.736069,46.542770 -65.500984)) How do I ...
0
votes
2answers
48 views

How to imitate a loop statement in math?

I need to iterate through expression several times and quit iteration process when certain value is reached but use algebraic notation. Summation notation would have worked if it didn't sum the ...
0
votes
1answer
45 views

Looking for row of an element in matrix

I have a $99$x$61$ matrix. The elements are indexed $1-6039$, vertically starting from the top left. So $X[1,1]$ is indexed $1$, $X[2,1]$ is indexed $2,...,X[1,2]$ is indexed $100,..., X[99,61]$ is ...
-1
votes
0answers
36 views

What does this subscript mean?

I was reading a paper about an old computer and there is a variable called Be. Be is the result of the calculation and further down in the paper, Be appears with a subscript of 0 and then +1 as a ...
2
votes
1answer
82 views

Logic puzzle: find negation of three logic variables using exactly two negations and any number of conjunctions and disjunctions

We're given a programming environment in which it is possible to introduce new logical variables and issue logical commands with operations AND, OR and NOT, such as A = (X AND Y) OR Z. However, TRUE ...
1
vote
2answers
36 views

Calculate the number of strings of length n containing Xs and Ys, knowing that p adjacent Xs are not allowed

Suppose we have a string of length N, containing only Xs and Ys, (example of a string of length 5: XYXYX). How can we calculate the number of strings of length N that do not contain P consecutive Xs (...
0
votes
1answer
20 views

Encoding numbers from 0 to 255 using Huffman coding.

How can I encode numbers from 0 to 255 using Huffman coding (or any other code), so that each number (especially the largest numbers such as 255) wouldn't take 8 bits of binary space? In other words, ...
0
votes
1answer
36 views

How to calculate probabilities for the next colour to be out in Wheel of Fortune Casino Game.

Recently i've been very interested in how to parse data from html into my c program. I'm now considering to calculating the probabilities for the next colour to be out in the Wheel of Fortune. But ...
0
votes
1answer
28 views

Can modulize a multiplication of some numbers

Let's suppose we have this function: $f(n)= a^n b^{n-1} c^{n-2} \mod p$, where $a,b,c,p \in Z^*$ and $p$ is also a prime. I want to create software in C, Java, etc., that calculates the function ...
0
votes
0answers
22 views

Computing coefficients of the generating function counting trees with forbidden members

How can I compute the coefficients $r^{(n)}_p$ with a Python code using the following equations? \begin{equation}\label{10} r^{(n)}(x)= S^{(n)}(x)-\frac{1}{2}\left[ (S^{(n)}(x))^2-S^{(n)}(x^2)\right] ...
1
vote
1answer
46 views

Almost all trees are cospectral (Allen Schwenk's 1973 article)

I am currently working on the following article: https://www.researchgate.net/publication/245264768_Almost_all_trees_are_cospectral. There are a few things that I don't understand, and since the ...
0
votes
0answers
16 views

Modular degree in PARI/GP

For a given elliptic curve $E$ over $\mathbb{Q}$ I'm trying to find its modular degree using the math software PARI/GP. There exists a built-in function called ellmoddegree(E), but for some reason, ...
0
votes
0answers
15 views

Find parameters for skewed standard distribution given the mean and bounds

I am working on a project but need to find a skewed standard distribution, and we can't figure out how. We have two variables: $p$, which is a probability and $PV$ which is an integer variable ...
0
votes
0answers
24 views

Are there any proof assistants based on logic programming?

Logic programming is a programming language paradigm. In it, a programmer creates a bunch of axioms in the form of horn clauses, representing computations, which the implementation of the language ...
1
vote
0answers
29 views

Linear algebra in a programming project (Preferably C)

I would like to merge both so I can improve my understanding and test my knowledge. I have been looking for ideas but I found nothing but strange research papers. Of course I am not looking for ...
1
vote
0answers
31 views

Number of Smaller permutations

I'm practicing programming and I found following problem that I don't know how to solve: We have 2 sequences A and B that both have length N. We should find number of different ways to permute ...
0
votes
0answers
59 views

How can I solve this problem with the help of dynamic programming?

I am preparing for a national algorithmic competition and I have encountered this question, You are given a string that contains only lowercase English letters. In one step, you can choose an index ...
0
votes
0answers
26 views

How can I find the max. sum of 'k' subarrays?

I am preparing for a national programming competition and I encountered this problem. It is as follows : - You are given an array of length M. You are required to select K non-intersecting ...
0
votes
0answers
21 views

What is the equation for calculating an investment with compounding interest and periodic contribution?

I am a begginner C# programmer working on a investment calculator as a personal project. I have not done much math in the last 15 years, please help. The parameters are: Principal - the original sum ...
1
vote
2answers
50 views

Number of triplets with same edge color in complete graph

I'm practicing for National programming competition and I came on this problem: We are given undirected complete graph with N vertices. Every edge in graph has color red or green. We should find ...
1
vote
2answers
38 views

Program or computing system [closed]

What programs do you suggest to me such that when introducing a set of numbers, it will answer possible functions that generate them? Different wolfram, neither OEIS. For example, if I input 2, 3, ...
2
votes
0answers
28 views

Efficient SQP with more equality constraints than parameters

My question is both a math and (computer) programming one so answers related to either are fine. Problem Setup I have the nonlinear programming problem $$ \begin{aligned} \min \;\; &f(X) \\ \...
0
votes
0answers
26 views

Expressing integers as summations

I've been trying to reduce the visual size of integers with up to a thousand digits by representing them with the summation operator. The only thing I've found that might be somewhat useful is some ...
2
votes
0answers
26 views

Weighted Random Generator

I've done a number of searches for this and haven't found what I'm looking for, although it's quite possible I'm not using the correct terms. I'm trying to write some code (Javascript, but the math ...
0
votes
0answers
14 views

Linear Programing Problem - how many basic solution are there in the Linearly independent set of the equation.

Given , $2 x_1 - x_2 + 3 x_3 + x_4 = 6$ $4 x_1 - 2 x_2 - 3 x_3 + 2 x_4 = 10$, I am using simplex method to calculate the non negative feasible solution for the given question, by the use ...
0
votes
3answers
29 views

Resizing and scaling image

I'm trying to resize image bitmap in software development, in that my requirement is as following, Get the original height of image Get the original width of image Set a max threshold, output height ...
0
votes
0answers
11 views

Average Error as Number of Samples Increases

I made a very simple program that approximates $\pi$ in r, by finding the probability that 2 random generated numbers are coprime for n trials. The result of this probability approaches $\frac{6}{\pi^...
0
votes
1answer
34 views

Combination of elements with a defined constraint (edited)

I'm trying to program a solution for this problem. So let's say I have a finite set elements ${X_{1},X_{2} , ..., X_{N}}$. To each element $X_{i}$ from the set, there is some assigned value, let's say ...
1
vote
1answer
79 views

what's the best programming language (and development community) for integer mathematics? [closed]

I was wondering what's the best programming language (and development community) for integer mathematics? I'm an R supporter. However, I'm interested in primality testing and integer factorization, ...
2
votes
1answer
77 views

Command to compute the number of $5$-colorings of all $(2k, k^2)$-graphs

I would like Sage to compute the number of all $5$-colorings of graphs on $2k$ vertices and $k^2$ edges with clique number 3 for a specified $k \geq 1$. I know how to ask call nauty and ask sage to ...
4
votes
2answers
82 views

Best programming language for solving numerical PDEs

I have been using matlab to write my finite difference, finite volume and level set codes when solving PDEs. The codes become even complicated hence taking longer to run when I go to 3D cases. This ...
2
votes
1answer
38 views

Creating an Equation for my Online Store

I have a site that I am building and I am trying to figure out how much to charge customers. I want to go as low as possible while maintaining a certain profit margin. Here are the perimeters: I want ...
0
votes
0answers
17 views

Optimization of the best element of the set of expressions - what kind of the optimization problem this is?

Let the following expression describes the conditional probability of the translation of the source sequence to the target sequence (e.g. for the sentence-to-sentence translation in the neural ...
8
votes
11answers
5k views

Can exact square roots not be found?

I'm brushing up on some higher level maths for a programming project. I was going along and then I realized that I have absolutely no idea how square roots can be computed. I mean sure, I've ...
0
votes
1answer
26 views

Trying to take a numerical integral involving the Lambert W function in R

I'm trying to get an approximate answer to the following integral: $\lim_{n \to \infty} \frac{n+1}{2} \int_1^{\ln(n)}xe^{-x}(1-\exp(-x - W(-xe^{-x})))^2 dx $ I'm currently just interested in if it ...
0
votes
1answer
27 views

Latex code required for drawing geodesic space

I want to draw that particular picture in $\LaTeX$ but does not getting the point how to make code in latex kindly give some suggestion:
0
votes
0answers
41 views

How to solve a non-convex programming problem?

Let $A$ and $C\ $ be $n\times n$ symmetric matrices, and $A\bullet C=Tr(A^TC)$. Let $S\subseteq [n]\times [n]\times [n]$. Define a non-convex programming problem as follows. \begin{equation} \begin{...
1
vote
0answers
37 views

Epidemic spacial diffusion problem.. how to draw a graph of differential system of second order with partial derivative

I'm currently working on how to simulate the diffusion of an epidemic in a population. If we don't consider that the population is moving in space, then the differential system is the following: ...
0
votes
2answers
59 views

How to calculate a “rational” sine/cosine to specific digits of precision?

I have a toy calculator I've been tasked to create for a class project. That's great - I have most of the normal calculator stuff done (order of operations, variables, precision settings, predefined ...
1
vote
1answer
20 views

How to use nPn in Burst Balloon problem with the given condition?

I was trying to understand this problem Burst Balloon . Mainly selecting the most efficient balloon to burst from the given condition. Given conditions are : Below is the condition to calculate the ...
1
vote
2answers
53 views

Eigenvalue problem - Right hand matrix is singular

I am constructing an eigenvalue problem of the form $$[R]{c} = \lambda [F]{c}$$ The matrices are populated by the results of some integrals $$ I_{i,j} = \int f(x,y,i,j) dxdy \quad for \quad i=1,..,...
2
votes
0answers
21 views

Can anyone explain to me the math behind this code ? Calculating a bullet's trajectory in 2D

following the book Beggining c++ game programming by John Horton on Chapter 9 the author explains us how our character can shoot a bullet, the thing is that there is very little explanations on what ...