algebra

Convert loop into mathematical equation

江枫思渺然 提交于 2019-12-13 09:58:11
问题 How would I represent this for loop in a mathematical equation? double n = 1; double x = Math.pow(3, n); for(double i = 0; i < n; i++){ x = x + Math.pow(3, i); } Sorry wrote it in Java in a hurry. 回答1: for loop can be simplifed to x= (pow(3,n)-1)/2 I have double checked this here: http://www.wolframalpha.com/input/?i=sum+pow%283%2Ci%29+for+i+from+0+to+%28n-1%29 来源: https://stackoverflow.com/questions/28392154/convert-loop-into-mathematical-equation

Algebra in Python (something better than a switch?)

巧了我就是萌 提交于 2019-12-13 00:21:33
问题 I've built a socket server that listens for commands from another client machine (the code to which I don't have access to). The client sends a number which relates to key strokes and sends a modifier code which relates to the modifier key presses. So for example shift=1 control=2 alt=4 win=8 The modifier code sent is always one number. e.g. modifier=1. But if more than 1 key is being sent it could be say modifier=3 (i.e. shift+control). The question is how I work out what the keys are from

How to calculate mean of distributed data?

人盡茶涼 提交于 2019-12-12 14:39:55
问题 How I can calculate the arithmetic mean of a large vector(series) in distributed computing where I partition the data on multiple nodes. I do not want to use map reduce paradigm. Is there any distributed algorithm to efficiently compute the mean besides the trivial computation of individual sum on each node and then bringing the result at master node and dividing with the size of the vector(series). 回答1: distributed average consensus is an alternative. The problem with the trivial approach of

Test if a point is approximately on a line segment formed by two other points

落爺英雄遲暮 提交于 2019-12-12 10:15:11
问题 I want to determine if a click is made between to points and roughly on the line segment that connects those two points. My question is similar to How can you determine a point is between two other points on a line segment? but it defers in two points: Im working in javascript and coordinates are in integers (pixels) The point do not have to be exactly on the line segment. A tolerance is needed. The following code is adapted from this answer, but I dont know how to insert a tolerance around

Theta Join in Relational Algebra Correctness

╄→гoц情女王★ 提交于 2019-12-12 05:32:58
问题 Considering these two tables: Band (band_id, band_name) Band_Member (band_id, member_name, dob, country, sex) The task: List the names of band members and the names of the bands they are in using the theta Join. Well, my doubt is in the step to show only the band_name and member_name after the join. This is how I've done the theta-join: σ Band_Member.band_id = Band.band_id (Band_member x Band) And this is how I think it might be correct to show only the band_name and member_name: Π band_name,

Solving two algebraic equations in java

风格不统一 提交于 2019-12-11 19:17:46
问题 I have two equations that need to be evaluated in java y=(x+1)*2-3 y=5 These equations are dynamic in nature y= x*8x6-5*5 y= 3 y is known in these equations, I need to determine the value of x What is the best and easy way to write a program in java? 回答1: It seems that there are a couple of ways to go about this. My first thought (as always is overly complex and most likely not worth doing except for fun), is to use a create a grammar to parse out the order of operations, things that can

GridLayout coordinates

こ雲淡風輕ζ 提交于 2019-12-11 10:46:59
问题 So I think you will understand my problem by this piece of code: int s = 4; int v = 4; world.setLayout(new GridLayout(s, v)); grid = new JLabel[s][v]; for (int x = s-1; x >= 0; x--) { for (int y = 0; y < v; y++) { grid[x][y] = new JLabel((x)+","+(y)); world.add(grid[x][y]); Now I get a grid with coordinates: 3,0 3,1 3,2 3,3 2,0 2,1 2,2 2,3 1,0 1,1 1,2 1,3 0,0 0,1 0,2 0,3 But I would like to get: 0,3 1,3 2,3 3,3 0,2 1,2 2,2 3,2 0,1 1,1 2,1 3,1 0,0 1,0 2,0 3,0 Any help appreciated.. 回答1: I didn

MATLAB sub2ind using vectors

懵懂的女人 提交于 2019-12-11 07:26:12
问题 Suppose I have a matrix A A = magic(5) 17 24 1 8 15 23 5 7 14 16 4 6 13 20 22 10 12 19 21 3 11 18 25 2 9 Now I select a block of this matrix using A(1:2, 1:2) 17 24 23 5 Now I need the linear index given by (1:2, 1;2) which are (1 2 6 7). Using sub2ind: sub2ind(size(A),[1:2], [1:2]) But this command returns just (1 7) how can I solve this? 回答1: Suppose you want to select A(1:2,2:3) : % Row and column indexes rind = 1:2; cind = 2:3; pos = bsxfun(@plus,rind', size(A,2)*(cind-1)); pos = 6 11 7

algebraic expressions in python

匆匆过客 提交于 2019-12-11 02:42:13
问题 I'm working with some relatively simple algebraic expressions in python and wondered if there's a better way of plotting algebraic expressions than what I'm currently doing: I have the equation of a notch filter (below image - left side from a book; the right side graph is the fig generated by my code), and so far my code works though is crude. Is there a better way of plotting the magnitude? As shown the constants are; R = 50.0, C = 470e-12, L = 54e-6, and the desired frequency range is from

SQL -> Relational Algebra

旧巷老猫 提交于 2019-12-10 17:50:50
问题 Suppose I have the following relations: Branch (branchNo(PK), street, city, postcode) Staff (staffNo(PK), fName, lName, sex, branchNo(FK)) Not that it matters for this question, but PK = primary key & FK = foreign key How would I write the relational algebra for the following query: List the names of all female staff that work in Glasgow. My attempt: σ Staff.sex=F & Branch.city = Glasgow (π fName, lName, sex, branchNo (Staff) x π city, branchNo (Branch)) I know that my selection (σ) statement