正如我理解你的问题,你有两个多项式,并希望找到它们相等的所有点。
这是一个函数,它使用Modelica.Math.Vectors.Utilities.roots
:
首先,你给出两个多项式poly1
和poly2
。查找poly1=poly2
与查找poly1-poly2=0
相同,因此我定义了第三个多项式polyDiff = polyLong-polyShort
,然后将该多项式移交给Modelica.Math.Vectors.Utilities.roots
。它会返回所有的根,甚至复杂的。
function polyIntersect
input Real[:] poly1={3,2,1,0};
input Real[:] poly2={8,7};
output Real[:,2] intersect;
protected
Integer nPoly1 = size(poly1,1);
Integer nPoly2 = size(poly2,1);
Integer nPolyShort = min(nPoly1, nPoly2);
Integer nPolyLong = max(nPoly1, nPoly2);
Real[nPolyShort] polyShort;
Real[nPolyLong] polyLong;
Real[nPolyLong] polyDiff;
algorithm
if (nPoly1<nPoly2) then
polyShort := poly1;
polyLong := poly2;
else
polyShort := poly2;
polyLong := poly1;
end if;
polyDiff := polyLong;
for i in 0:nPolyShort-1 loop
polyDiff[nPolyLong-i] := polyLong[nPolyLong-i] - polyShort[nPolyShort-i];
end for;
intersect := Modelica.Math.Vectors.Utilities.roots(polyDiff);
end polyIntersect;
上面的代码也可以在这里:https://gist.github.com/thorade/5388205
你已经来看看'Modelica.Math.Vectors.Utilities.roots'?这是计算多项式根的函数。如果有帮助,你应该在这里写一个简短的例子作为自我回答。 – matth 2013-04-14 15:40:17