2016-03-12 62 views
1

我無法解決Scilab中的問題,因爲它由於舍入錯誤而陷入困境。我得到的消息Scilab舍入錯誤

!--error 9999 
Error: Round-off error detected, the requested tolerance (or default) cannot be achieved. Try using bigger tolerances. 
at line  2 of function scalpol called by : 
at line  7 of function gram_schmidt_pol called by : 
gram_schmidt_pol(a,-1/2,-1/2) 

它是一種革蘭氏施密特過程有兩個函數的乘積的積分和重量標產品,-1和1 gram_schmidt_pol是專爲polynome設計的過程中,和之間scalpol是針對polynome描述的標量積。

ab是用於weigth,這是(1+x)^a*(1-x)^b

該條目是表示一組向量的矩陣的參數,它與基質[[1;2;3],[4;5;6],[7;8;9]]效果很好,但它無法與基體中的上述消息錯誤eye(2,2),除此之外,我需要在眼睛上做(9,9)!

我已經在菜單中尋找「容差設置」,有一些在General->Preferences->Xcos->Simulation,但我相信這不是我想要的,我已經嘗試過低設置(高容忍度),並且它沒有'不改變任何事情。

那麼,我該如何解決這個問題?

隨時告訴我我的消息缺乏清晰度。 謝謝。

編輯:代碼的功能:

// function that evaluate a polynomial (vector of coefficients) in x 
function [y] = pol(p, x) 
    y = 0 
    for i=1:length(p) 
     y = y + p(i)*x^(i-1) 
    end 
endfunction 

// weight function evaluated in x, parametrized by a and b 
// (poids = weight in french) 
function [y] = poids(x, a, b) 
    y = (1-x)^a*(1+x)^b 
endfunction 

// scalpol compute scalar product between polynomial p1 and p2 
// using integrate, the weight and the pol functions. 
function [s] = scalpol(p1, p2, a, b) 
    s = integrate('poids(x,a, b)*pol(p1,x)*pol(p2,x)', 'x', -1, 1) 
endfunction 

// norm associated to scalpol 
function [y] = normscalpol(f, a, b) 
    y = sqrt(scalpol(f, f, a, b)) 
endfunction 

// finally the gram schmidt process on a family of polynome 
// represented by a matrix 
function [o] = gram_schmidt_pol(m, a, b) 
    [n,p] = size(m) 
    o(1:n) = m(1:n,1)/(normscalpol(m(1:n,1), a, b)) 
    for k = 2:p 
     s =0 
     for i = 1:(k-1) 
      s = s + (scalpol(o(1:n,i), m(1:n,k), a, b)/scalpol(o(1:n,i),o(1:n,i), a, b) .* o(1:n,i)) 
     end 
     o(1:n,k) = m(1:n,k) - s 
     o(1:n,k) = o(1:n,k) ./ normscalpol(o(1:n,k), a, b) 
    end 
endfunction 
+0

是的,我編輯帖子 –

回答

0

默認情況下,Scilab的的integrate例程試圖以最1E-14實現最多1E-8和相對誤差絕對誤差。這是合理的,但是對相對誤差的處理沒有考慮到確切值爲零時發生的問題。 (見How to calculate relative error when true value is zero?)。出於這個原因,即使是簡單的

integrate('x', 'x', -1, 1) 

拋出一個錯誤(Scilab的5.5.1)。

這就是運行程序的過程中發生的情況:一些積分爲零。有兩種解決辦法:

(A)放棄對結合的相對誤差,通過將其指定爲1:

integrate('...', 'x', -1, 1, 1e-8, 1) 

(B)一些常數添加到功能集成,然後從結果中減去:

integrate('100 + ... ', 'x', -1, 1) - 200 

(後者在大多數情況下工作,但如果積分恰好是準確-200,你會再次出現相同的問題)


上面的作品爲gram_schmidt_pol(eye(2,2), -1/2, -1/2),但對於較大的,比如gram_schmidt_pol(eye(9,9), -1/2, -1/2),它會拋出錯誤「積分可能發散,或者慢慢收斂」。

似乎自適應整合例程無法處理您擁有的功能。後退是使用簡單的inttrap,它只是應用梯形法則。由於在x = -1和1處,函數poids是未定義的,因此必須排除端點。

function [s] = scalpol(p1, p2, a, b) 
    t = -0.9995:0.001:0.9995 
    y = poids(t,a, b).*pol(p1,t).*pol(p2,t) 
    s = inttrap(t,y) 
endfunction 

爲了這個工作,其他相關職能必須被矢量(*和^改爲*和^必要。):

function [y] = pol(p, x) 
    y = 0 
    for i=1:length(p) 
     y = y + p(i)*x.^(i-1) 
    end 
endfunction 

function [y] = poids(x, a, b) 
    y = (1-x).^a.*(1+x).^b 
endfunction 

結果是保證工作,雖然精度可能會稍微降低一些:您將獲得一些像3D-16這樣的數字,它們實際上是零。

+0

謝謝,但我很抱歉,這兩種方法不適合我。 –

+0

用Scilab 5.5.1在我的電腦上工作。命令'gram_schmidt_pol(eye(2,2),-1/2,-1/2)'返回矩陣0.5683590 0. // 0. 0.8080328。 –

+0

我有5.5.2。它很糟糕,我需要它來完成我明天的作業,並且因爲Scilab問題而陷入困境! GRRRR! 如果只有我可以在Python或OCaml中做... –