Ein Algorithmus muß beide Spektren abhängig vom lokalen Umfeld durchlaufen um die richtigen Stützstellen ,
,
und
zur Interpolation parat zu haben und
zu entscheiden, wie wir zum nächsten Schritt weiterrücken, indem wir entweder
oder
oder Beide hochzählen.
Dabei dürfen
und
Werte zwischen dem Anfang 0 und ihrem Maximalwert minus 1 annehmen.
Abbildung zeigt die Situation, bei der die aktuellen Zählerpositionen zu weit auseinanderliegen.
Durch sukzessives Erhöhung von
Haben wir uns durch Erhöhung von und
immer weiter durch die Ausgangsspektren gearbeitet, kommen wir irgendwann an den Endpunkt,
an dem
oder
ist. Es gibt an dieser Stelle keine Vorschau über diesen Punkt hinaus und
wir müssen den letzten Punkt von der rückwärtigen Seite interpolieren.
Die rückwärtige Seite
oder
gibt es natürlich nur, wenn
oder
bereits einmal hochgezählt wurden,
also größer Null sind. Das ist nicht immer der Fall, beispielsweise wenn ein Spektrum mit 2 Stützstellen
alle Stützstellen des anderen Spektrums umschließt.
In den Fällen, bei denen
oder
Null sind, können wir jedoch immer getrost um Eins hochzählen, denn zwei Stützstellen gibt es immer.
Sonst ist es kein Bereich und es gibt kein Integral.
Für den Fall dass
den Endpunkt erreicht hat und
ist wäre die letzte Stützstelle dann
1 2 function durchhangelnmul(spek1, spek2){ 3 var s=0,i=0,j=0, arr=[]; 4 while (i < spek1.length-1 && j< spek2.length-1) { 5 if(spek1[i]["x"]>=spek2[j+1]["x"]){j++; continue;}; 6 if(spek2[j]["x"]>=spek1[i+1]["x"]){i++; continue;}; 7 8 if(spek1[i]["x"]==spek2[j]["x"]){ 9 arr.push({x:spek1[i]["x"], y: spek1[i]["y"]*spek2[j]["y"]}); 10 }; 11 if(spek1[i]["x"]<spek2[j]["x"]){ 12 arr.push({x:spek2[j]["x"], y: (spek1[i]["y"] + (spek1[i+1]["y"]- spek1[i]["y"]) / (spek1[i+1]["x"] - spek1[i]["x"]) * (spek2[j]["x"] - spek1[i]["x"])) * spek2[j]["y"] }); 13 }; 14 15 if(spek1[i]["x"]>spek2[j]["x"]){ 16 arr.push({x:spek1[i]["x"], y: (spek2[j]["y"] + (spek2[j+1]["y"]- spek2[j]["y"]) / (spek2[j+1]["x"] - spek2[j]["x"]) * (spek1[i]["x"] - spek2[j]["x"])) * spek1[i]["y"] }); 17 }; 18 if(spek1[i+1]["x"]==spek2[j+1]["x"]){i++; j++; continue;}; 19 if(spek1[i+1]["x"]<spek2[j+1]["x"]){i++; continue;}; 20 if(spek1[i+1]["x"]>spek2[j+1]["x"]){j++; continue;}; 21 } 22 /*************Letztes Element************/ 23 if(i==spek1.length-1){ 24 arr.push({x:spek1[i]["x"], y: (spek2[j-1]["y"] + (spek2[j]["y"]- spek2[j-1]["y"]) / (spek2[j]["x"] - spek2[j-1]["x"]) * (spek1[i]["x"] - spek2[j-1]["x"])) * spek1[i]["y"] }); 25 //console.log("i:arr[arr.length-1]",arr[arr.length-1]); 26 }else{ 27 arr.push({x:spek2[j]["x"], y: (spek1[i-1]["y"] + (spek1[i]["y"]- spek1[i-1]["y"]) / (spek1[i]["x"] - spek1[i-1]["x"]) * (spek2[j]["x"] - spek1[i-1]["x"])) * spek2[j]["y"] }); 28 } 29 return arr; 30 } |
1 2 Public Function Durchmultiplizieren(ByRef U As Variant, ByRef V As Variant) As Variant() 3 Dim F() As Variant: ReDim F(1, 0) 4 Dim i As Long, j As Long: i = 0: j = 0 5 Do While i < UBound(V, 2) And j < UBound(U, 2) 6 If V(0, i) >= U(0, j + 1) Then j = j + 1: GoTo ContinueLoop 7 If U(0, j) >= V(0, i + 1) Then i = i + 1: GoTo ContinueLoop 8 If U(0, j) = V(0, i) Then 9 If Not IsEmpty(F(1, UBound(F, 2))) Then ReDim Preserve F(1, UBound(F, 2) + 1) 10 F(0, UBound(F, 2)) = V(0, i) 11 F(1, UBound(F, 2)) = U(1, j) * V(1, i) 12 'Debug.Print i; j, F(0, UBound(F, 2)); F(1, UBound(F, 2)); "= "; U(1, j); "*"; V(1, i) 13 GoTo Weiter 14 End If 15 If U(0, j) < V(0, i) Then 16 If Not IsEmpty(F(1, UBound(F, 2))) Then ReDim Preserve F(1, UBound(F, 2) + 1) 17 F(0, UBound(F, 2)) = V(0, i) 18 F(1, UBound(F, 2)) = (U(1, j) + (U(1, j + 1) - U(1, j)) / (U(0, j + 1) - U(0, j)) * (V(0, i) - U(0, j))) * V(1, i) 19 'Debug.Print i; j, F(0, UBound(F, 2)); F(1, UBound(F, 2)); "= ("; U(1, j); "+("; U(1, j + 1); "-"; U(1, j); ")/("; U(0, j + 1); "-"; U(0, j); ")*("; V(0, i); "-"; U(0, j); "))*"; V(1, i) 20 GoTo Weiter 21 End If 22 If U(0, j) > V(0, i) Then 23 If Not IsEmpty(F(1, UBound(F, 2))) Then ReDim Preserve F(1, UBound(F, 2) + 1) 24 F(0, UBound(F, 2)) = U(0, j) 25 F(1, UBound(F, 2)) = (V(1, i) + (V(1, i + 1) - V(1, i)) / (V(0, i + 1) - V(0, i)) * (U(0, j) - V(0, i))) * U(1, j) 26 'Debug.Print i; j, F(0, UBound(F, 2)); F(1, UBound(F, 2)); "= ("; V(1, i); "+("; V(1, i + 1); "-"; V(1, i); ")/("; V(0, i + 1); "-"; V(0, i); ")*("; U(0, j); "-"; V(0, i); "))*"; U(1, j) 27 GoTo Weiter 28 End If 29 Weiter: 30 If V(0, i + 1) = U(0, j + 1) Then i = i + 1: j = j + 1: GoTo ContinueLoop 31 If V(0, i + 1) < U(0, j + 1) Then i = i + 1: GoTo ContinueLoop 32 If V(0, i + 1) > U(0, j + 1) Then j = j + 1: GoTo ContinueLoop 33 ContinueLoop: 34 Loop 35 '***************letztes Element****************** 36 If j = UBound(U, 2) Then 37 i = IIf(i = 0, 1, i) 38 'Debug.Print ; ; , V(0, i); (U(1, j - 1) + (U(1, j) - U(1, j - 1)) / (U(0, j) - U(0, j - 1)) * (V(0, i) - U(0, j - 1))) * V(1, i); 39 'Debug.Print "= ("; U(1, j - 1); "+("; U(1, j); "-"; U(1, j - 1); ")/("; U(0, j); "-"; U(0, j - 1); ")*("; V(0, i); "-"; U(0, j - 1); "))*"; V(1, i) 40 If Not IsEmpty(F(1, UBound(F, 2))) Then ReDim Preserve F(1, UBound(F, 2) + 1) 41 F(0, UBound(F, 2)) = U(0, j) 42 F(1, UBound(F, 2)) = (V(1, i - 1) + (V(1, i) - V(1, i - 1)) / (V(0, i) - V(0, i - 1)) * (U(0, j) - V(0, i - 1))) * U(1, j) 43 'Debug.Print "X" 44 ElseIf i = UBound(V, 2) Then 45 j = IIf(j = 0, 1, j) 46 'Debug.Print ; ; , V(0, i); (U(1, j - 1) + (U(1, j) - U(1, j - 1)) / (U(0, j) - U(0, j - 1)) * (V(0, i) - U(0, j - 1))) * V(1, i); 47 'Debug.Print "= ("; U(1, j - 1); "+("; U(1, j); "-"; U(1, j - 1); ")/("; U(0, j); "-"; U(0, j - 1); ")*("; V(0, i); "-"; U(0, j - 1); "))*"; V(1, i) 48 If Not IsEmpty(F(1, UBound(F, 2))) Then ReDim Preserve F(1, UBound(F, 2) + 1) 49 F(0, UBound(F, 2)) = V(0, i) 50 F(1, UBound(F, 2)) = (U(1, j - 1) + (U(1, j) - U(1, j - 1)) / (U(0, j) - U(0, j - 1)) * (V(0, i) - U(0, j - 1))) * V(1, i) 51 End If 52 Durchmultiplizieren = F 53 End Function |