正如我理解你的問題,你有兩個多項式,並希望找到它們相等的所有點。
這是一個函數,它使用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