discrete-mathematics

Find a minimum spanning tree

南笙酒味 提交于 2019-12-11 19:51:23
问题 Could you please tell me why this MATLAB code is wrong? I don't understand why. Thank you so much in advance. function [mst, cost] = prim(A) [n,n] = size(A); A, n, pause, if norm(A-A','fro') ~= 0 , disp(' Error: Adjacency matrix must be symmetric ') return, end; intree = [1]; number_in_tree = 1; number_of_edges = 0; notintree = [2:n]'; number_notin_tree= n-1; in = intree(1:number_in_tree), out = notintree(1:number_notin_tree), pause, while number_in_tree < n, mincost = Inf; for i=1:number_in

How to find the coordinates of a line in HTML5 Canvas

ⅰ亾dé卋堺 提交于 2019-12-11 08:46:42
问题 I am developing a Building Plan Drawing Application in HTML5. For that I needed to place the doors and windows on walls. Usually, the walls (lines) are not straight. How can I find if my mouse has touched the walls (lines) while moving the door Image. Moreover, I should find the X, Y and angle of the door to be drawn. Please help... 回答1: Here's one way: Save all your line segments (walls) in an array. var walls=[]; var wall={x0:50,y0:50,x1:150,y1:150}; walls.push(wall); When you are dragging

figure out Uneaten Leaves algorithm bug

天涯浪子 提交于 2019-12-10 18:28:32
问题 I faced this problem in an interview challenge K caterpillars are eating their way through N leaves, each caterpillar falls from leaf to leaf in a unique sequence, all caterpillars start at a twig at position 0 and falls onto the leaves at position between 1 and N. Each caterpillar j has an associated jump number Aj. A caterpillar with jump number j eats leaves at positions that are multiple of j. It will proceed in the order j, 2j, 3j…. till it reaches the end of the leaves and it stops and

Why does my php code return inf?

江枫思渺然 提交于 2019-12-10 13:27:54
问题 I have a math problem where I am trying to calculate the total combination of values in a set... when I try and run my calculation it just returns INF instead of a number... $tally = 1; foreach ($output as $key => $er) { $tally = $tally *(ord(strtolower($er)) - 96); } echo $tally; 回答1: If when you try and echo a number and isntead PHP gives you "INF", it is because PHP thinks that the number is infinite, or too large to be stored in its memory. You can confirm this by echo is_infinite($tally)

i need to find the upper bound of this: or the tight bound:

人走茶凉 提交于 2019-12-10 11:56:05
问题 lets say i have an expression: (n)+((n-1)*2)+((n-2)*3)+((n-3)*4)+...+(3*(n-2))+(2*(n-1))+(1*(n)) what is the tight bound of this? or the upper bound? is this n^3? is this n^4? the maximum amount of number i can get out of this? thanks EDIT: so: for i=1 then: the ans is 1. i=2: (1*2 + 2*1) 1=3: (1*3 + 2*2 + 3*1) i=4: (1*4 + 2*3 + 3*2 + 4*1 ) and so on 回答1: Try Wolfram Alpha ... Sum[(i + 1) (n - i), {i, 0, n - 1}] 来源: https://stackoverflow.com/questions/4382014/i-need-to-find-the-upper-bound-of

How to perform discrete optimization of functions over matrices?

夙愿已清 提交于 2019-12-10 02:26:54
问题 I would like to optimize over all 30 by 30 matrices with entries that are 0 or 1. My objective function is the determinant. One way to do this would be some sort of stochastic gradient descent or simulated annealing. I looked at scipy.optimize but it doesn't seem to support this sort of optimization as far as I can tell. scipy.optimize.basinhopping looked very tempting but it seems to require continuous variables. Are there any tools in Python for this sort of general discrete optimization?

Looking for C/C++ library calculating max of Gaussian curve using discrete values

这一生的挚爱 提交于 2019-12-09 07:56:58
问题 I have some discrete values and assumption, that these values lie on a Gaussian curve. There should be an algorithm for max-calculation using only 3 discrete values. Do you know any library or code in C/C++ implementing this calculation? Thank you! P.S.: The original task is auto-focus implementation. I move a (microscope) camera and capture the pictures in different positions. The position having most different colors should have best focus. EDIT This was long time ago :-( I'just wanted to

What is the number of all set permutations in a power set?

*爱你&永不变心* 提交于 2019-12-08 09:58:47
问题 For a set of size n , the size of its power set is 2^n . Generate all permutations for each element of the power set. The power set for set {a, b} is {{}, {a}, {b}, {a,b}} . Generate all permutations on each set, we can get {(),(a),(b),(a,b),(b,a)} . So the number of all subset permutation for a power set generated from a 2-element set is 5. And such a number for a 3-item set is 16. Is there a formula for this number defined in terms of n ? 回答1: First of all, consider the power set. The

Parma Polyhedra Library: Vertex Enumeration

梦想的初衷 提交于 2019-12-07 20:01:33
问题 I'm trying to use the Parma Polyhedra Library [1] to enumerate the vertices of a (convex) polytope, e.g., I have a rectangle specified by four constraints: Constraint_System cs; cs.insert(x >= 0); cs.insert(x <= 3); cs.insert(y >= 0); cs.insert(y <= 3); C_Polyhedron ph(cs); How do I generate the vertices? 回答1: Each shape in PPL has dual representations: 1) Constraint_System, 2) Generator_System. For a convex-polyhedra, the generator system will contain the set of generators which can either

Fox-Goat-Cabbage Transportation

纵然是瞬间 提交于 2019-12-07 18:30:03
问题 My question is about an old transportation problem -- carrying three items across a river with a boat only capable of tranferring one item at a time. A constraint is certain items cannot be left together, such as the cabbage with the goat, wolf with the goat etc. This problem should be solveable using Integer programming, or another optimization approach. The cost function is all items being on the other side of the river, and the trips required to get there could be the output from Simplex (