天道酬勤,学无止境

algebra

测试一个点是否近似在由另外两个点形成的线段上(Test if a point is approximately on a line segment formed by two other points)

问题 我想确定是否在点之间以及连接这两个点的线段上大致进行了单击。 我的问题类似于如何确定一个点位于线段上的其他两个点之间? 但它推迟了两点: 我在 javascript 中工作,坐标是整数(像素) 该点不必正好位于线段上。 需要宽容。 以下代码改编自此答案,但我不知道如何在线段周围插入公差 a和b是线段的端点, c是单击的点。 我想检查c是否在a和b之间,并且大致在连接a和b的线段上 PencilTool.prototype._isBetween = function(a,b,c){ //test if a, b and c are aligned var crossproduct = (c.y - a.y) * (b.x - a.x) - (c.x - a.x) * (b.y - a.y); if(Math.abs(crossproduct) !== 0){ return false; } var dotproduct = (c.x - a.x) * (b.x - a.x) + (c.y - a.y)*(b.y - a.y) if(dotproduct < 0){ return false } var squaredlengthba = (b.x - a.x)*(b.x - a.x) + (b.y - a.y)*(b.y - a.y); if(dotproduct >

2021-09-22 05:17:01    分类:技术分享    javascript   linear-algebra   algebra

python中的代数表达式(algebraic expressions in python)

问题 我正在 python 中使用一些相对简单的代数表达式,想知道是否有比我目前正在做的更好的绘制代数表达式的方法: 我有一个陷波滤波器的方程(下图 - 书的左侧;右侧图是我的代码生成的无花果),到目前为止,我的代码虽然很粗糙。 有没有更好的绘制幅度的方法? 如图所示,常数是; R = 50.0,C = 470e-12,L = 54e-6,所需频率范围为 0 至 2MHz。 import matplotlib.pyplot as plt import numpy as np import math R = 50.0 C = 470e-12 L = 54e-6 FREQ = [] DATA = [] for i in range(1, 200): f = i*10000.0 w = 2*np.pi*f Ztop = w*L - 1.0/(w*C) Zbot = math.sqrt( (math.pow(R,2) + math.pow((w*L) -(1.0/(w*C)),2)) ) Zout = abs(Ztop / Zbot) FREQ.append( f/1e6 ) DATA.append( Zout ) plt.figure(1) plt.plot(FREQ,DATA, '-k') plt.xlabel('Frequency (MHz)') plt.ylabel('Mag.')

2021-09-12 10:53:56    分类:技术分享    python   plot   algebra

How can I construct a matrix given a generator for this cyclic group?

Let F[q^p] be a finite cyclic set of polynomials, where q is a prime number and p is an integer greater than 0. Each element in F[q^p] will be a polynomial up to degree (p-1) under (mod q). Ex: F[2^2]={0,1,x,1+x} Ex: F[3^4]={0,1,2,0+x,1+x,2+x,0+x^2,1+x^2,2+x^2,x+x^2,1+x+x^2,2+x+x^2,2x+x^2,1+2x+x^2,2+2x+x^2,0+2x^2,1+2x^2,2+2x^2,x+2x^2,1+x+2x^2,2+x+2x^2,2x+2x^2,1+2x+2x^2,2+2x+2x^2,...,2+2x+2x^2+2x^3} Thus, there will be q^p elements in F[q,p]. Assume that we have a generator theta, where theta^k, where k=0,1,2,...,q^p-1, will generate the entire finite cyclic set F[q^p]. Let's examine the more

2021-09-03 09:05:52    分类:问答    r   for-loop   matrix   generator   algebra

algebraic expressions in python

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 0 to 2MHz. import matplotlib.pyplot as plt import numpy as np import math R = 50.0 C = 470e-12 L = 54e

2021-09-02 18:15:56    分类:问答    python   plot   algebra

Element by element tensor multiplication in python

I am trying to solve a problem in computational algebra using python. Basically given two sets, say A={a,b} and B={e}, I need to compute the element by element tensor products and get a final set say C={a\tensor{e},b\tensor{e}} containing these products of elements. I can do an element by element multiplication using arrays with numbers but I can't do an element by element tensor multiplication of letters instead of numbers.

2021-09-01 10:16:34    分类:问答    math   set   algebra   tensor

计算多项式系数(Calculate multinomial coefficient)

问题 我想计算多项系数 mod 1e9 + 7。它等于:n! /(k0!* k1!* k2 * ... * 公里!) 在我的情况下,m = 3,k0 + k1 + k2 = n,所以它是:n! / (k0!* k1! * k2!) 我的代码: .... long long k2 = n - k1 - k0; long long dans = fact[n] % MOD; long long tmp = fact[i] % MOD; tmp = (tmp * fact[j]) % MOD; tmp = (tpm * fact[k]) % MOD; res = (fact[n] / tmp) % MOD; // mb mistake is here... cout << res; fact[i] - i mod 1e9+7 的阶乘 它不适用于大型测试 回答1 我希望我不是在这里链接农业,但这里有一个工作过程,可以解决您的问题: 幼稚的实现总是会遇到溢出错误。 您必须准备好利用多项式系数的某些数学特性来获得稳健的解决方案。 Dave Barber在他的库中这样做,其中使用了递归属性(例如 4 个数字 - 当所有分支都被零替换时递归停止) multi (a, b, c, d) = multi (a − 1, b, c, d) + multi (a, b − 1, c, d) + multi

2021-08-30 13:12:40    分类:技术分享    c++   combinatorics   algebra

Problems with formula to output a triangle waveform in Java

I got my wave file creator working and I split it into three classes, I also made a sinewave generator that inherits from an abstract class called waveform and I can export 8 and 16 bit mono or sterio sine waves. I am trying to make a class called TriangleWave Generator to output a triangle wave tone, but I can't get the algebra from https://en.wikipedia.org/wiki/Triangle_wave#, the first formula, to work. It will only export the highest harmonic stated and not blend them together with the fundamental Sample length: length in seconds point: individual sample amp limit: the highest position

2021-08-30 11:13:02    分类:问答    java   algebra   waveform

自学线性代数的书籍和资源[关闭](Books & resources to teach myself Linear Algebra [closed])

问题 就目前而言,这个问题不适合我们的问答形式。 我们希望答案得到事实、参考或专业知识的支持,但这个问题可能会引起辩论、争论、投票或扩展讨论。 如果您认为此问题可以改进并可能重新打开,请访问帮助中心以获取指导。 9年前关闭。 我在寻找书籍和资源,以教我线性代数在3D图形编程中使用。 我更喜欢实用的教学方法而不是理论的教学方法(即使数学是什么,99.99% 的理论?),所以我梦想的资源是一本解决线性代数的书,因为它从实践的角度与 3D 图形编程一起使用。 回答1 MIT OpenCourseWare 提供免费的线性代数课程。 对于您的特定兴趣可能过于笼统,但它是免费的。 :) 回答2 如果你问数学家、工程师和游戏程序员什么是线性代数,你会得到三个不同的答案。 数学家将专注于迷人但抽象的主题,例如线性独立性和抽象向量空间。 工程师将专注于用于求解微分方程的特征向量。 对于图形,您通常使用向量来计算几何,这不是线性代数教科书的重点。 一本好的计算机图形教科书应该涵盖您需要的大部分内容。 FS Hill 的书就是一个例子。 回答3 虽然不打算教授线性代数,但“3d 游戏编程大师的技巧”一书对 3D 图形有很好的覆盖,并提供了如何应用线性代数的示例。 回答4 Foley's Computer Graphics将以实用的方式回答您的问题。 回答5 嗯 - 对于 3D 编程

2021-08-12 09:58:52    分类:技术分享    math   linear-algebra   algebra

寻找两条线的交点(Finding the intersection of two lines)

问题 我有两行: y = -1/3x + 4 y = 3x + 85 交点在[24.3, 12.1] 。 我准备了一组坐标: points = [[1, 3], [4, 8], [25, 10], ... ] #y = -1/3x + b m_regr = -1/3 b_regr = 4 m_perp = 3 #(1 / m_regr * -1) distances = [] points.each do |pair| x1 = pair.first y2 = pair.last x2 = ((b_perp - b_regr / (m_regr - m_perp)) y2 = ((m_regr * b_perp) / (m_perp * b_regr))/(m_regr - m_perp) distance = Math.hypot((y2 - y1), (x2 - x1)) distances << distance end 有没有宝石或更好的方法? 注意:上述方法不起作用。 请参阅我的答案以获取有效的解决方案。 回答1 使用一点数学有什么问题? 如果你有: y = m1 x + b1 y = m2 x + b2 这是一个简单的线性方程组。 如果你解决了它们,你的交集是: x = (b2 - b1)/(m1 - m2) y = (m1 b2 - m2 b1)/(m1 - m2)

2021-08-11 18:09:16    分类:技术分享    ruby   intersection   algebra

Calculating the boundary of irregular shape in Cartesian Coordinate 2D

I'm looking for a solution to calculate the boundary of an irregular shape. Lats take a look at Square example: if i have Minimum x and y and Maximum x and y like: MaxX = 5 MinX = 1 MaxY = 5 MinY = 1 in python language: #Python Code X = {"Min":1, "Max":5} # is Dictionary of x Axis Y = {"Min":1, "Max":5} # is Dictionary of y Axis I can check if any coordinate is in the square boundary or not, simpley by comparing the axis against min and max of square boundary. now let's look at these 2 irregular example: Now how can i calculate the boundary and coordinates of the shape? i do have the point

2021-08-01 21:04:52    分类:问答    python   math   algebra   calculus