math

undefined reference to `log'

天大地大妈咪最大 提交于 2020-01-22 04:50:28
问题 I am trying to compile the implementation of the RFC 3797 random selection algorithm by Donald Eastlake (code: http://kambing.ui.ac.id/minix/other/rfc3797/). However, I am getting a linker error: rfc3797.c:(.text+0xe7f): undefined reference to `log' I am trying to make it with the provided Makefile, which explicitly links against the math libraray, but I still get the error: cc -lm -o randomselection rfc3797.c MD5.c How can I compile this program? 回答1: I don't know what the reason is, but if

undefined reference to `log'

心不动则不痛 提交于 2020-01-22 04:50:05
问题 I am trying to compile the implementation of the RFC 3797 random selection algorithm by Donald Eastlake (code: http://kambing.ui.ac.id/minix/other/rfc3797/). However, I am getting a linker error: rfc3797.c:(.text+0xe7f): undefined reference to `log' I am trying to make it with the provided Makefile, which explicitly links against the math libraray, but I still get the error: cc -lm -o randomselection rfc3797.c MD5.c How can I compile this program? 回答1: I don't know what the reason is, but if

3D Line - Plane intersection?

守給你的承諾、 提交于 2020-01-22 03:00:45
问题 I am having two Vectors (X,Y,Z), one above Y=0 and one below Y=0 . I want to find the Vector (X,Y,Z) where the line between the two original vectors intersects with the Y=0 level. How do I do that? Example Point A: X = -43.54235 Y = 95.2679138 Z = -98.2120361 Example Point B: X = -43.54235 Y = 97.23531 Z = -96.24464 These points read from two UnProjections from a users click and I'm trying to target the unprojection to Y=0 . (I found 3D line plane intersection, with simple plane but didn't

Multiplication and division: weird output in c

自作多情 提交于 2020-01-22 01:32:30
问题 I read that * (multiplication) has has higher presedence than / (division). Thus if there is an equation with both * and / , then * must take place first. But I've seen a program that output something strange #include<stdio.h> #define SQUARE(x) x*x int main() { float s=10, u=30, t=2, a; a = 2*(s-u*t)/SQUARE(t); printf("Result = %f", a); return 0; } When running this, I thought that the output would be -25, but in fact it was -100. When I looked for the explanation it was Step 2: a = 2*(s-u*t)

Multiplication and division: weird output in c

余生长醉 提交于 2020-01-22 01:31:33
问题 I read that * (multiplication) has has higher presedence than / (division). Thus if there is an equation with both * and / , then * must take place first. But I've seen a program that output something strange #include<stdio.h> #define SQUARE(x) x*x int main() { float s=10, u=30, t=2, a; a = 2*(s-u*t)/SQUARE(t); printf("Result = %f", a); return 0; } When running this, I thought that the output would be -25, but in fact it was -100. When I looked for the explanation it was Step 2: a = 2*(s-u*t)

Math.cos inaccurancy

淺唱寂寞╮ 提交于 2020-01-21 12:04:30
问题 alert(Math.cos(Math.PI/2)); Why the result is not exact zero? Is this inaccurancy, or some implementation error? 回答1: Math.PI/2 is an approximation of the real value of pi/2 . Taking the exact cosine of this approximated value won't yield zero. The value you get is an approximation of this exact value up to the precision of the underlying floating point datatype. Using some arbitrary precision library, you can evaluate the difference between pi/2 in double precision and the exact value to 0

Java - Detect Straight Lines with given Coordinates

心不动则不痛 提交于 2020-01-21 11:48:07
问题 ADDED INFO: I'm using the inside of a square as an arena. On start up, the square spawns in a random position, and rotation, and I can't access any of the squares attributes. I then have a moving object inside the square, that I'm building AI for, and I want the object to 'learn' where the arena walls are. Every time the object bumps into a wall, I get a touch return, so I know if its hit or not. I'm using this to map the global position of where the object hit the wall and save it ... After

How to divide x number of players into 2 teams randomly multiple times, differently every time?

拜拜、爱过 提交于 2020-01-21 09:08:12
问题 I have a mathematical problem in my JavaScript code. I need to divide a given number of players into 2 teams randomly so that each time – if players want to play again – the teams are formed again and they should be different until all the combinations are formed. Let's say I have 4 players, so all the combinations are as follows: [1,2],[1,3],[1,4],[2,3],[2,4],[3,4] However, because the team side doesn't count, there are only 3 different combinations: [1,2] vs [3,4] [1,3] vs [2,4] [1,4] vs [2

How can you perform this improper integral as Mathematica does?

此生再无相见时 提交于 2020-01-21 09:01:49
问题 Take this Mathematica code: f[x_] := Exp[-x]; c = 0.9; g[x_] := c*x^(c - 1)*Exp[-x^c]; SetPrecision[Integrate[f[x]*Log[f[x]/g[x]], {x, 0.001, \[Infinity]}],20] Mathematica computes this without problem and gives the answer 0.010089328699390866240 . I would like to be able to perform similar integrals but I don't have a copy of Mathematica. Just naively implementing it in scipy, for example, using a standard quadrature library fails sadly because f(x) and g(x) get arbitrarily close to 0. Here

How to pass a function as a function parameter in Python

别等时光非礼了梦想. 提交于 2020-01-21 07:16:46
问题 This is what I currently have and it works fine: def iterate(seed, num): x = seed orbit = [x] for i in range(num): x = 2 * x * (1 - x) orbit.append(x) return orbit Now if I want to change the iterating equation on line 5 to, say, x = x ** 2 - 3, I'll have to create a new function with all the same code except line 5. How do I create a more general function that can have a function as a parameter? 回答1: Functions are first-class citizens in Python. you can pass a function as a parameter: def