Matlab的数字精度

时间:2018-08-08 12:27:17

标签: matlab

我正在使用matlab并输入三个函数:IntegralAddtoIntegralTerm1AddtoIntegralTerm2。我想添加三个数字,所以我将其写为如下 Integral(0,139)+AddtoIntegralTerm1(0,139)+AddtoIntegralTerm2(0,139),这给了我一个数字1048576

但是,当我将其除以1e21(计算每个数字的顺序为1e21)并相加后,即Integral(0,139)/1e21+AddtoIntegralTerm1(0,139)/1e21+AddtoIntegralTerm2(0,139)/1e21时,我得到一个数字0。精度?如何解决?下面列出了这些功能:

        % Use of indefinite integral
    pit=@(t)-MinOrMax.*...
        (-1./lambda.*(exp(-lambda.*min(t,CutOff)))-(lambda.*beta)./(sigma.^2).*exp(-lambda.*t));
    pitau=@(tau)MinOrMax.*...
        (-1./lambda.*(exp(-lambda.*min(tau,CutOff)))-(lambda.*beta)./(sigma.^2).*exp(-lambda.*tau));
    vt=@(t)-MinOrMax.*sigma.^2.*...
        (1./(lambda.^2).*(exp(lambda.*min(t,CutOff)))+...
        ...
        exp(-lambda.*CutOff)./(2.*lambda.^2).*(exp(2.*lambda.*t)-exp(2.*lambda.*min(t,CutOff)))+...
        ...
        (lambda.*beta)./(sigma.^2.*lambda).*(exp(lambda.*t)));
    vtau=@(tau)-MinOrMax.*sigma.^2.*...
        (1./(lambda.^2).*(exp(lambda.*min(tau,CutOff)))+...
        ...
        exp(-lambda.*CutOff)./(2.*lambda.^2).*(exp(2.*lambda.*tau)-exp(2.*lambda.*min(tau,CutOff)))+...
        ...
        (lambda.*beta)./(sigma.^2.*lambda.^2).*(exp(lambda.*tau)));

    Integral1=...
        @(t,tau)sigma.^2./(2.*lambda.^2).*...
        (1./(2.*lambda).*exp(-2.*lambda.*CutOff).*(exp(2.*lambda.*tau)-exp(2.*lambda.*t)).*(CutOff<t)+...
        ...
        ((CutOff-t)+exp(-2.*lambda.*CutOff)./(2.*lambda).*...
        (exp(2.*lambda.*tau)-exp(2.*lambda.*CutOff))).*((CutOff<=tau).*(CutOff>=t))+...
        ...
        (tau-t).*(CutOff>=tau));
    Integral2=...
        @(t,tau)2.*((lambda.*beta)./sigma.^2).*sigma.^2./(2.*lambda).*...
        (1./lambda.*exp(-lambda.*CutOff).*(exp(lambda.*tau)-exp(lambda.*t)).*(CutOff<t)+...
        ...
        ((CutOff-t)+exp(-lambda.*CutOff)./(lambda).*...
        (exp(lambda.*tau)-exp(lambda.*CutOff))).*((CutOff<=tau).*(CutOff>=t))+...
        ...
        (tau-t).*(CutOff>=tau));
    Integral3=@(t,tau)sigma.^2./2.*((lambda.*beta)./sigma.^2).^2.*(tau-t);
    Integral=@(t,tau)Integral1(t,tau)+Integral2(t,tau)+Integral3(t,tau);

    AddtoIntegralTerm1=@(t,tau)sigma.^2./(2.*lambda).*pitau(tau).^2.*(exp(2.*lambda.*tau)-exp(2.*lambda.*t))./2;
    AddtoIntegralTerm2=@(t,tau)-pitau(tau).*vtau(tau);

感谢您的帮助。

0 个答案:

没有答案