DELPHI盒子
!实时搜索: 盒子论坛 | 注册用户 | 修改信息 | 退出
检举帖 | 全文检索 | 关闭广告 | 捐赠
技术论坛
 用户名
 密  码
自动登陆(30天有效)
忘了密码
≡技术区≡
DELPHI技术
lazarus/fpc/Free Pascal
移动应用开发
Web应用开发
数据库专区
报表专区
网络通讯
开源项目
论坛精华贴
≡发布区≡
发布代码
发布控件
文档资料
经典工具
≡事务区≡
网站意见
盒子之家
招聘应聘
信息交换
论坛信息
最新加入: lambdaflow
今日帖子: 0
在线用户: 10
导航: 论坛 -> DELPHI技术 斑竹:liumazi,sephil  
作者:
女 xiaokeliang (xiaoke) ★☆☆☆☆ -
普通会员
2004/5/2 21:11:19
标题:
要把double型的数据转换成string型输出到窗口上,怎么才能办到呢? 浏览:1066
加入我的收藏
楼主: 这是我编的一段代码,但是老是出问题:例如什么。。invalid floating point operating

 a,u:integer; 
 a0:array[0..1] of double;
  ........
  ........
  u:=round(a0[0*1+0]);
  a:=round(a0[1*1+0]);
  xx:=round(x[0]);
  label2.Caption:='['+inttostr(xx)+'-'+inttostr(u)+
  '/'+inttostr(a)+']'+'e^'+inttostr(a)+'k'+'+'+
  inttostr(u)+'/'+inttostr(a);
  ........
大家有谁能解决我的这个问题呢?回复以下,都讨论讨论。
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/2 21:36:14
1楼: 系统有自带函数 看来你是 初学的吧 floattostr
此帖子包含附件:
JPEG 图像
大小:88.4K
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
女 xiaokeliang (xiaoke) ★☆☆☆☆ -
普通会员
2004/5/2 22:16:49
2楼: 谢谢楼上的,我的确是初学的

我原先就是用的floattostr,后来就是因为出现了我先前说的问题,我才把floattostr改成了inttostr,不知道为什么,改了之后还是没有改变,所以我才不得不求助于高手们了。
难道不是转换的问题??
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/2 22:27:37
3楼: 估计不是 你的算法偶看不懂 不过估计是你的 逻辑问题 这个得自己搞定!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
作者:
男 sephil (NAILY Soft) ★☆☆☆☆ -
盒子中级会员
2004/5/3 7:23:45
4楼: 你代码里的x和xx哪里来的?
你单步执行看看问题出在哪里
----------------------------------------------
Copyright 2008 ? NAILY Soft

Click here to redirect to my home
Click here to redirect to my blog
作者:
女 xiaokeliang (xiaoke) ★☆☆☆☆ -
普通会员
2004/5/3 10:13:37
5楼: x:array[0..17] of double;
xx:integer;

x数组在前面已赋值,如下是这个窗口的全部代码,要求的是矩阵的计算:

unit nsl;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, ToolWin, ComCtrls, StdCtrls, Buttons;

type
  Tyc_huice = class(TForm)
    Edit1: TEdit;
    Edit2: TEdit;
    Edit3: TEdit;
    Edit4: TEdit;
    Edit5: TEdit;
    Edit6: TEdit;
    Edit7: TEdit;
    Edit8: TEdit;
    Edit9: TEdit;
    Edit10: TEdit;
    Edit11: TEdit;
    Edit12: TEdit;
    Edit13: TEdit;
    Edit14: TEdit;
    Edit15: TEdit;
    Edit16: TEdit;
    Edit17: TEdit;
    Edit18: TEdit;
    SpeedButton1: TSpeedButton;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    procedure SpeedButton1Click(Sender: TObject);

  private
    { Private declarations }

  public
    { Public declarations }

  end;

var
  yc_huice: Tyc_huice;
type
  PReal=array of double;
function MatrixOpp(A :array of double;m, n :integer) :PReal;
function  MatrixInver(A:array of double; m,n :integer) :PReal;
function Surplus(A :array of double; m, n :integer) :real;
implementation

{$R *.dfm}
  uses Math;




function MatrixOpp(A :array of double;m, n :integer) :PReal;
var
     i,j,x,y,k :integer;
     SP,AB, B,C :PReal;
     X1 :double;
begin
     Setlength(SP, m*n*sizeof(double));
     Setlength(AB,  m*n*sizeof(double));
     Setlength(B, m*n*sizeof(double));
     X1 :=Surplus(A,m,n);
     X1 :=1/X1;
   for i :=0 to m do 
   for j :=0 to n do
   begin
      for k:=0 to m*n  do begin
      B[k]:=A[k];
      begin
       for x:=0 to n do 
         B[i*n+x] :=0;
     for y:=0 to m do
        B[m*y+j] :=0; 
     B[i*n+j] :=1; 
     SP[i*n+j] :=Surplus(B,m,n); 
     AB[i*n+j] :=X1*SP[i*n+j];
     end;
     end;
     end;
     C :=MatrixInver(AB,m,n);
     Result := C;
     Exit;
 end;

function  MatrixInver(A:array of double; m,n :integer) :PReal; //*矩阵转置*/
var
     i,j :integer;
     B :PReal;
begin
     Setlength(B, m*n*sizeof(double));
     for i :=0 to n do
     for j :=0 to m do
       B[i*m+j] :=A[j*n+i];
     Result := B;
    end;

  function Surplus(A :array of double; m, n :integer) :real; //*求矩阵行列式*/
var     i,j,k,p,r :integer;
     X,temp,temp1,s,s1 :double;
  begin
     temp:=1; temp1:=1; s:=0; s1:=0;
     if(n=2) then
     begin
       for i :=0 to m do 
       for j :=0 to n do 
       if((i+j) mod 2 <> 0) then temp1 :=temp1 * A[i*n+j]
       else temp := temp *A[i*n+j]; 
       X :=temp-temp1;
     end
     else
     begin
       for k :=0 to n do 
       begin
        j := k;
        for i :=0 to m do 
        begin
          temp := temp * A[i*n+j]; 
          if j < n then inc(j)
        end;

     if (m-i) <>0 then
     begin
      r :=m-1;
      for p := m-i downto 0 do  
      begin         
         temp := temp * A[r*n+p-1];
         dec(r); 
      end;
    end;
      s :=s + temp; 
     temp :=1; 
   end; 
     for k :=n-1 downto 0 do
     begin
       j := k; 
       for i :=0 to m do
       begin  
         temp1 := temp1 *A[i*n+j];  
         dec(j);
       end;
     if(m-i) <>0 then
     begin
      r := i; 
      for p :=m-1 downto m do 
      begin  
         temp1:= temp1*A[r*n+p];
         inc(r);
      end;
     end;
     s1 := s1 + temp1; 
     temp1 :=1; 
    end;
     X :=s-s1;
   end;
     result := X; 
  end;



procedure Tyc_huice.SpeedButton1Click(Sender: TObject);
var
   yuan:array[0..17] of double;
   x,xy,xh,ek:array[0..17] of double;
   xk,e,ej,xj,s1,s2,c,s11,p,m,ai:double;
   i,j,k,count,xx:integer;
   a,u:integer; a0:array[0..1] of double;
   B,BT,BTB,BTB1,BTB2:PReal;
begin
count:=17;
//   Setlength(yuan, 0*17*sizeof(Real));
   yuan[0]:=0;yuan[1]:=0;yuan[2]:=0;yuan[3]:=0;yuan[4]:=0;yuan[5]:=0; yuan[6]:=0;yuan[7]:=0;yuan[8]:=0;yuan[9]:=0;yuan[10]:=0;yuan[11]:=0;yuan[12]:=0;yuan[13]:=0;yuan[14]:=0;yuan[15]:=0;yuan[16]:=0; yuan[17]:=0;
   x[0]:=0;x[1]:=0;x[2]:=0;x[3]:=0;x[4]:=0;x[5]:=0;x[6]:=0;x[7]:=0;x[8]:=0;x[9]:=0;x[10]:=0;x[11]:=0;x[12]:=0;x[13]:=0;x[14]:=0;x[15]:=0;x[16]:=0;
   yuan[0]:=strtofloat(edit1.Text);yuan[1]:=strtofloat(edit2.Text);yuan[0*0+2]:=strtofloat(edit3.Text);yuan[0*0+3]:=strtofloat(edit4.Text);yuan[0*0+4]:=strtofloat(edit5.Text);yuan[0*0+5]:=strtofloat(edit6.Text);
   yuan[6]:=strtofloat(edit7.Text);yuan[7]:=strtofloat(edit8.Text);yuan[0*0+8]:=strtofloat(edit9.Text);yuan[0*0+9]:=strtofloat(edit10.Text);yuan[0*0+10]:=strtofloat(edit11.Text);yuan[0*0+11]:=strtofloat(edit12.Text);
   yuan[12]:=strtofloat(edit13.Text);yuan[0*0+13]:=strtofloat(edit14.Text);yuan[0*0+14]:=strtofloat(edit15.Text);yuan[0*0+15]:=strtofloat(edit16.Text);yuan[0*0+16]:=strtofloat(edit17.Text); yuan[0*0+17]:=strtofloat(edit18.Text);
   //将原始数据作一次累加生成
   for i:=0 to count do begin
     for j:=0 to i do begin
     x[i]:=yuan[j]+x[i];
     end;
   end;
//计算参数a,u
  Setlength(B, (count-1)*1*sizeof(double));
 // Setlength(a0, 1*0*sizeof(double));
//  Setlength(BT, 1*(count-2)*sizeof(Real));
  Setlength(BTB, 1*1*sizeof(double));
  Setlength(BTB2, 1*(count-1)*sizeof(double));
//  Setlength(YN, (count-1)*0*sizeof(double));
  for i:=0 to count-1 do begin
     B[i+0]:=-0.5*(x[i]+x[i+1]);
     B[i+1]:=1;
     end;
//  for i:=0 to count-1 do
//    YN[i]:=yuan[i+1];
  BT:=MatrixInver(B,count-1,1);
  for i:=0 to 3 do                   //求BTb
       BTB[i]:=0;
  for i:=0 to 1 do begin
     for j:=0 to 1 do begin
        for k:=0 to count-1 do
        BTB[i*1+j]:=B[i+k]*BT[k*1+j]+BTB[i*1+j];
     end;
  end;
  BTB1:=MatrixOpp(BTB,1,1);                  //求BTB的逆

  for i:=0 to 1 do
   for j:=0 to count-1 do
     for k:=0 to count-1 do
     BTB2[i*(count-1)+j]:=BTB1[i*1+k]*BT[k*(count-1)+j]+BTB2[i*(count-1)+j];


     a0[0]:=0;a0[1]:=0;

  for i:=0 to 1 do begin

    for k:=0 to count-1 do
      a0[i]:=BTB2[i*(count-1)+k]*yuan[k+1]+a0[i];
  end;
  u:=round(a0[0*1+0]);
  a:=round(a0[1*1+0]);
  xx:=round(x[0]);
  label2.Caption:='['+inttostr(xx)+'-'+inttostr(u)+
  '/'+inttostr(a)+']'+'e^'+inttostr(a)+'k'+'+'+
  inttostr(u)+'/'+inttostr(a);
  e:=2.7;
  ej:=0; xj:=0;s1:=0;s2:=0;c:=0;p:=0;  

 m:=0;
  xy[0]:=x[0];
  xh[0]:=xy[0];
  if a<>0 then  begin
  xk:=(yuan[0]-u/a)*power(e,a*count)+u/a;
    for i:=1 to count do   begin
       xy[i]:=(yuan[0]-u/a)*power(e,a*i)+u/a;
       xh[i]:=xy[i]-xy[i-1];
       ek[i]:=yuan[i]-xh[i];
       ej:=mean(ek);
        xj:=mean(yuan);                     //求原始数据均值
 s1:=popnstddev(yuan);              //求原始数据标准差
 s2:=popnstddev(ek);
 
 c:=s2/s1;
 s11:=0.6745*s1;
   if (ek[i]-ej>s11) or (ek[i]-ej<s11) then
      m:=m+1;
  p:=m/(count+1);
  end;
  end
  else
    begin
    xk:=0;
    xy[i]:=0;
    end;

  //计算x^(k+1),预测值的还原


                   //模型精度检验: 求预测误差
               //求预测均值


 // if p<=0.7 or c>=0.65 then//确定预测精度

end;

e
----------------------------------------------
-
作者:
男 bios (阿贡) ★☆☆☆☆ -
盒子中级会员
2004/5/3 11:06:20
6楼: 太多 人 没耐心帮你看 偶们自己都有项目要写!
----------------------------------------------
按此在新窗口浏览图片
按此在新窗口浏览图片
信息
登陆以后才能回复
Copyright © 2CCC.Com 盒子论坛 v3.0.1 版权所有 页面执行97.00012毫秒 RSS