鱼C论坛

 找回密码
 立即注册
查看: 401|回复: 3

[已解决]关于C语言和python语言数学运算的问题

[复制链接]
发表于 2020-4-15 22:17:21 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
问题背景:本人初学python,最近在完成学校里老师留的大作业,将祖传的C语言代码改成Python语言代码,在改的过程中发现两组代码产生的数据不同,想向fishc大佬们求助。
代码如下:
  1. Python代码
  2. import numpy as np
  3. #from numba import jit

  4. rho = 2850
  5. E = 7.154*1e10
  6. X = np.array([
  7.     0.0, 0.01, 0.02, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.10
  8. ])
  9. A = np.array([
  10.     1.7*1e-4, 1.46*1e-4, 1.26*1e-4, 1.09*1e-4, 0.96*1e-4, 0.86*1e-4, 0.77*1e-4, 0.73*1e-4, 0.7*1e-4, 0.68*1e-4, 0.68*1e-4
  11. ])
  12. I = np.array([
  13.     2.79*1e-10, 2.12*1e-10, 1.57*1e-10, 1.08*1e-10, 0.84*1e-10, 0.61*1e-10, 0.45*1e-10, 0.37*1e-10, 0.32*1e-10, 0.30*1e-10, 0.30*1e-10
  14. ])
  15. Y0js = np.array([
  16.     0, 0.1, 0.2, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
  17. ])
  18. Y2js = np.array([
  19.     0, -0.1, -0.3, -0.5, -0.4, -0.2, -0.1, 0.5, 0.8, 1.0
  20. ])
  21. Y3js = np.array([
  22.     0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0
  23. ])

  24. Y0sj = np.zeros(10)
  25. Y0xxx = np.zeros(10)
  26. Y2 = np.zeros(10)
  27. Y2sj = np.zeros(10)
  28. Y3 = np.zeros(10)
  29. Y3sj = np.zeros(10)

  30. xz = 2.58

  31. # midpoint function
  32. def midpoint(x):
  33.     return (x[:-1]+x[1:])/2.0

  34. def _1st(Ab, Ib, Y0js, Y0sj, Y0xxx):
  35.     dev = 10

  36.     while dev >= 1e-6:
  37.         
  38.         _1st = np.zeros(10)
  39.         _2nd = np.zeros(10)
  40.         _3rd = np.zeros(10)
  41.         _4th = np.zeros(10)
  42.         
  43.         #cycle 1
  44.         a, b = 0 ,0
  45.         while a <= 9:
  46.             b = a
  47.             while b <= 8:
  48.                 _1st[a] +=  Ab[b+1] * Y0js[b+1] * 0.01
  49.                 b += 1
  50.             a += 1
  51.         
  52.         #cycle 2
  53.         a, b = 0 ,0
  54.         while a <= 9:
  55.             b = a
  56.             while b <= 8:
  57.                 _2nd[a] += _1st[b+1] * 0.01
  58.                 b += 1
  59.             a += 1
  60.       
  61.         #cycle 3
  62.         a, b = 0 ,0
  63.         while a <= 9:
  64.             b = 0
  65.             while a >= b:
  66.                 _3rd[a] += _2nd[b] * 0.01 * (1/Ib[b])
  67.                 b += 1
  68.             a += 1
  69.         
  70.         #cycle 4
  71.         a, b = 0 ,0
  72.         while a <= 9:
  73.             b = 0
  74.             while a >= b:
  75.                 _4th[a] += _3rd[b] * 0.01
  76.                 b += 1
  77.             a += 1

  78.         a = 0
  79.         while a <= 9:
  80.             Y0sj[a] = _4th[a] / _4th[9]
  81.             Y0xxx[a] = _4th[a]
  82.             a += 1
  83.         
  84.         dev = 0
  85.         a = 0
  86.         while a <= 9:
  87.             dev += abs(Y0js[a] - Y0sj[a])
  88.             a += 1
  89.         
  90.         a = 0
  91.         while a <= 9:
  92.             Y0js[a] = Y0sj[a]
  93.             a += 1
  94.    
  95.     return 5000 * _4th[9] **-0.5 / 2 / np.pi

  96. def _2nd(E, xz, rho, Ab, Ib, Y0xxx, Y2js, Y2, Y2sj):
  97.     a21 = 10

  98.     while abs(a21) >= 1e-8:
  99.         b11 = 0
  100.         c21 = 0
  101.         a21 = 0

  102.         i = 0
  103.         while i <= 9:
  104.             b11 += 2850 * Ab[i] * Y0xxx[i] **2 * 0.01
  105.             i += 1
  106.         
  107.         i = 0
  108.         while i <= 9:
  109.             c21 += 2850 * Ab[i] * Y0xxx[i] * Y2js[i] * 0.01
  110.             i += 1

  111.         a21 = c21 / b11

  112.         i = 0
  113.         while i <= 9:
  114.             Y2[i] = Y2js[i] - a21 * Y0xxx[i]
  115.             i += 1
  116.         
  117.         i = 0
  118.         while i <= 9:
  119.             Y2js[i] = Y2[i]
  120.             i += 1
  121.         
  122.     i = 0
  123.     while i <= 9:
  124.         Y2sj[i] = Y2[i] / Y2[9]
  125.         i += 1
  126.    
  127.     _1st = np.zeros(10)
  128.     _2nd = np.zeros(10)
  129.     _3rd = np.zeros(10)
  130.     _4th = np.zeros(10)

  131.     #cycle 1
  132.     a, b = 0 ,0
  133.     while a <= 9:
  134.         b = a
  135.         while b <= 7:
  136.             _1st[a] +=  Ab[b+2] * Y2sj[b+2] * 0.01
  137.             b += 1
  138.         a += 1
  139.    
  140.     #cycle 2
  141.     a, b = 0 ,0
  142.     while a <= 9:
  143.         b = a
  144.         while b <= 8:
  145.             _2nd[a] += _1st[b+1] * 0.01
  146.             b += 1
  147.         a += 1
  148.    
  149.     #cycle 3
  150.     a, b = 0 ,0
  151.     while a <= 9:
  152.         b = 0
  153.         while a >= b:
  154.             _3rd[a] += _2nd[b] * 0.01 * (1/Ib[b])
  155.             b += 1
  156.         a += 1
  157.    
  158.     #cycle 4
  159.     a, b = 0 ,0
  160.     while a <= 9:
  161.         b = 0
  162.         while a >= b:
  163.             _4th[a] += _3rd[b] * 0.01
  164.             b += 1
  165.         a += 1
  166.    
  167.     return (E / rho / _4th[9]) ** 0.5 / 2 / np.pi * xz

  168. def _3rd(E, rho, Ab, Ib, Y0xxx, Y2js, Y2, Y2sj, Y3, Y3js):
  169.     cvg = 10
  170.     b11, b12, b21, b22, c31, c32, a31, a32 = 0, 0, 0, 0, 0, 0, 0, 10
  171.     i = 10
  172.     while cvg >= 1e-4:
  173.         
  174.         #while i <= 9:
  175.         #    Y3js[i] = Y3[i]
  176.         #    i += 1

  177.         b12, b21, b22, c31, c32, a31 = 0, 0, 0, 0, 0, 0

  178.         i = 0
  179.         while i <= 9:
  180.             b11 += 2850 * Ab[i] * Y0xxx[i] **2 * 0.01
  181.             i += 1
  182.         
  183.         i = 0
  184.         while i <= 9:
  185.                 b12 += 2850 * Ab[i] * Y0xxx[i] * Y2[i] * 0.01
  186.                 i += 1

  187.         i = 0
  188.         while i <= 9:
  189.                 b21 += 2850 * Ab[i] * Y0xxx[i] * Y2[i] * 0.01
  190.                 i += 1

  191.         i = 0
  192.         while i <= 9:
  193.                 #b22 += 2850 * Ab[i] * Y2[b] * Y2[i] * 0.01
  194.             b22 += 2850 * Ab[i] * Y2[9] **2 * 0.01
  195.             i += 1

  196.         i = 0
  197.         while i <= 9:
  198.                 c31 += 2850 * Ab[i] * Y0xxx[i] * Y3js[i] * 0.01
  199.                 i += 1

  200.         i = 0
  201.         while i <= 9:
  202.                 c32 += 2850 * Ab[i] * Y2[i] * Y3js[i] * 0.01
  203.                 i += 1
  204.         
  205.         a31 = c31 / b11
  206.         a32 = c32 / b22
  207.         
  208.         i=0
  209.         while i <= 9:
  210.                 Y3[i] = Y3js[i] - a31 * Y0xxx[i] - a32 * Y2[i]
  211.                 i += 1
  212.         
  213.         cvg = abs(Y3js[0] - Y3[0])

  214.     _1st = np.zeros(10)
  215.     _2nd = np.zeros(10)
  216.     _3rd = np.zeros(10)
  217.     _4th = np.zeros(10)

  218.     #cycle 1
  219.     a, b = 0 ,0
  220.     while a <= 9:
  221.         b = a
  222.         while b <= 7:
  223.             _1st[a] +=  Ab[b+2] * Y3[b+2] * 0.01
  224.             b += 1
  225.         a += 1
  226.    
  227.     #cycle 2
  228.     a, b = 0 ,0
  229.     while a <= 9:
  230.         b = a
  231.         while b <= 8:
  232.             _2nd[a] += _1st[b+1] * 0.01
  233.             b += 1
  234.         a += 1
  235.    
  236.     #cycle 3
  237.     a, b = 0 ,0
  238.     while a <= 9:
  239.         b = 0
  240.         while a >= b:
  241.             _3rd[a] += _2nd[b] * 0.01 * (1/Ib[b])
  242.             b += 1
  243.         a += 1
  244.    
  245.     #cycle 4
  246.     a, b = 0 ,0
  247.     while a <= 9:
  248.         b = 0
  249.         while a >= b:
  250.             _4th[a] += _3rd[b] * 0.01
  251.             b += 1
  252.         a += 1
  253.    
  254.     return (E / rho / _4th[9]) ** 0.5 * cvg /np.pi

  255. if __name__ == "__main__":
  256.    
  257.     Ab = midpoint(A)
  258.     Ib = midpoint(I)

  259.     omega_1 = _1st(Ab, Ib, Y0js, Y0sj, Y0xxx)
  260.     omega_2 = _2nd(E, xz, rho, Ab, Ib, Y0xxx, Y2js, Y2, Y2sj)
  261.     omega_3 = _3rd(E, rho, Ab, Ib, Y0xxx, Y2js, Y2, Y2sj, Y3, Y3js)
  262.     print(omega_1)
  263.     print(omega_2)
  264.     print(omega_3)
复制代码

  1. C代码
  2. #include<stdio.h>
  3. #include<math.h>
  4. #include<stdlib.h>
  5. int main(void)
  6. {
  7.         float rou=2850;
  8.         float E=71540000000;
  9.         float X[11]={0.0,0.01,0.02,0.03,0.04,0.05,0.06,0.07,0.08,0.09,0.10};
  10.         float A[11]={0.00017,0.000146,0.000126,0.000109,0.000096,0.000086,0.000077,0.000073,0.00007,0.000068,0.000068};
  11.         float I[11]={0.000000000279,0.000000000212,0.000000000157,0.000000000108,0.000000000084,0.000000000061,0.000000000045,0.000000000037,0.000000000032,0.000000000030,0.000000000030};
  12.         float Ab[10];
  13.         float Ib[10];
  14.        
  15.         int i=0;
  16.         while(i<=9)
  17.         {
  18.                   Ab[i]=((A[i+1]+A[i])/2);
  19.                   i=i+1;
  20.         }
  21.        
  22.         i=0;
  23.         while(i<=9)
  24.         {
  25.                   Ib[i]=((I[i+1]+I[i])/2);
  26.                   i=i+1;
  27.         }
  28.        
  29.         //第一个函数开始
  30.         float Y0js[10]={0,0.1,0.2,0.4,0.5,0.6,0.7,0.8,0.9,1};
  31.         float Y0sj[10]={0,0,0,0,0,0,0,0,0,0};
  32.         float Y0xxx[10]={0,0,0,0,0,0,0,0,0,0};
  33.         float one[10]={0,0,0,0,0,0,0,0,0,0};
  34.         float two[10]={0,0,0,0,0,0,0,0,0,0};
  35.         float three[10]={0,0,0,0,0,0,0,0,0,0};
  36.         float four[10]={0,0,0,0,0,0,0,0,0,0};
  37.         float wucha=10;
  38.         float xz=2.58;
  39.         int a=0;
  40.         int b=0;
  41.         int c=0;
  42.         int d=0;
  43.         int e=0;
  44.         int f=0;
  45.         int g=0;
  46.         int h=0;
  47.         int j=0;
  48.         int k=0;
  49.         int p=0;
  50.         int q=0;
  51.         while(wucha>=0.000001)                  //给定拟合精确度
  52.         {
  53.                    q=0;
  54.                    while(9>=q)
  55.             {
  56.                       one[q]=0;
  57.                       two[q]=0;
  58.                       three[q]=0;
  59.                       four[q]=0;
  60.                       q=q+1;
  61.                    }                             //这步是给数组清零,千万不能忘!
  62.                   
  63.                 a=0;
  64.                    b=9;
  65.             while(9>=a)
  66.                 {
  67.                       b=a;
  68.                       while(9>=b+1)
  69.                         {
  70.                           one[a]=one[a]+(Ab[b+1]*Y0js[b+1]*0.01);
  71.                           b=b+1;
  72.                       }   
  73.                 a=a+1;
  74.                 }                                         //第一重循环
  75.                
  76.                 c=0;
  77.             d=0;
  78.                    while(9>=c)
  79.             {
  80.                       d=c;
  81.                       while(9>=d+1)
  82.                 {
  83.                               two[c]=two[c]+(one[d+1]*0.01);
  84.                           d=d+1;
  85.                 }
  86.                 c=c+1;
  87.             }                                 //第二重循环

  88.                 e=0;
  89.             f=0;
  90.             while(9>=e)
  91.             {
  92.                         f=0;
  93.                       while(e>=f)
  94.                 {
  95.                           three[e]=three[e]+two[f]*0.01*(1/Ib[f]);
  96.                           f=f+1;
  97.                 }
  98.                 e=e+1;
  99.             }                                 //第三重循环  
  100.    
  101.                 g=0;
  102.             h=0;
  103.             while(9>=g)
  104.             {
  105.                       h=0;
  106.                       while(g>=h)
  107.                 {
  108.                                  four[g]=four[g]+three[h]*0.01;
  109.                                  h=h+1;
  110.                 }
  111.                 g=g+1;
  112.             }                                 //第四重循环
  113.    
  114.             k=0;
  115.             while(9>=k)
  116.             {
  117.                       Y0sj[k]=four[k]/four[9];
  118.                       Y0xxx[k]=four[k];
  119.                           k=k+1;
  120.               }                                //求出实际y0,以便和假设yo对比迭代
  121.    
  122.             wucha=0;
  123.            
  124.             j=0;
  125.             while(j<=9)
  126.               {
  127.                       wucha=wucha+fabs(Y0js[j]-Y0sj[j]);
  128.                       j=j+1;
  129.               }                                 //假设的y0与求出y0之间的误差  
  130.    
  131.             p=0;
  132.             while(9>=p)
  133.              {
  134.                       Y0js[p]=Y0sj[p];
  135.                 p=p+1;
  136.             }                                 //令实际值等于假设值,再次迭代运算
  137.    }
  138.         float omega=0;
  139.         omega=5000*sqrt((1/four[9]));
  140.         printf("一阶固有静频为:%.5fHZ\n",omega/(2*3.1415926));  
  141.        
  142.         //第二个函数开始
  143.         float Y2js[10]={0,-0.1,-0.3,-0.5,-0.4,-0.2,-0.1,0.5,0.8,1};
  144.         float Y2[10]={0,0,0,0,0,0,0,0,0,0};
  145.         float xiuzhen=4;
  146.         float Y2sj[10]={0,0,0,0,0,0,0,0,0,0};
  147.         float b11=0;
  148.         float C21=0;
  149.         float a21=0;
  150.         a21=10;

  151.         while(fabs(a21)>=0.00000001)                  //给定拟合精确度
  152.         {
  153.                    b11=0;
  154.                    C21=0;
  155.                    a21=0;
  156.                
  157.                 i=0;
  158.                 while(i<=9)
  159.                 {
  160.                         b11=b11+2850*Ab[i]*Y0xxx[i]*Y0xxx[i]*0.01;
  161.                         i++;
  162.                 }
  163.                
  164.                 i=0;
  165.                 while(i<=9)
  166.                 {
  167.                         C21=C21+2850*Ab[i]*Y0xxx[i]*Y2js[i]*0.01;
  168.                         i++;
  169.                 }
  170.                
  171.                 a21=C21/b11;

  172.                 i=0;
  173.                 while(i<=9)
  174.                 {
  175.                         Y2[i]=Y2js[i]-a21*Y0xxx[i];
  176.                         i++;
  177.                 }

  178.                 p=0;
  179.             while(9>=p)
  180.             {
  181.                       Y2js[p]=Y2[p];
  182.                 p=p+1;
  183.             }                                 //令实际值等于假设值,再次迭代运算
  184.    }
  185.                
  186.                 i=0;
  187.                 while (i<=9)
  188.                 {
  189.                         Y2sj[i]=Y2[i]/Y2[9];
  190.                            i++;       
  191.                    }                                     //归一化
  192.                  
  193.                 q=0;
  194.                    while(9>=q)
  195.         {
  196.                   one[q]=0;
  197.                   two[q]=0;
  198.                   three[q]=0;
  199.                   four[q]=0;
  200.                   q=q+1;
  201.         }                             //这步是给数组清零,千万不能忘!
  202.            
  203.                 a=0;
  204.             b=0;
  205.             while(9>=a)
  206.             {
  207.                       b=a;
  208.                       while(9>=b+2)
  209.                 {
  210.                           one[a]=one[a]+(Ab[b+2]*Y2sj[b+2]*0.01);
  211.                           b=b+1;
  212.                   }
  213.                 a=a+1;
  214.               }                                 //第一重循环

  215.             c=0;
  216.             d=0;
  217.             while(9>=c)
  218.             {
  219.                           d=c;
  220.                       while(9>=d+1)
  221.                 {
  222.                           two[c]=two[c]+(one[d+1]*0.01);
  223.                           d=d+1;
  224.                 }
  225.                 c=c+1;
  226.             }                                 //第二重循环
  227.   
  228.             e=0;
  229.             f=0;
  230.             while(9>=e)
  231.             {
  232.                       f=0;
  233.                       while(e>=f)
  234.                 {
  235.                           three[e]=three[e]+two[f]*0.01*(1/Ib[f]);
  236.                           f=f+1;
  237.                 }
  238.                 e=e+1;
  239.             }                                 //第三重循环  
  240.    
  241.             g=0;
  242.             h=0;
  243.             while(9>=g)
  244.             {
  245.                       h=0;
  246.                       while(g>=h)
  247.                 {
  248.                                  four[g]=four[g]+three[h]*0.01;
  249.                                  h=h+1;
  250.                 }
  251.                 g=g+1;
  252.               }                                 //第四重循环
  253.    
  254.         omega=sqrt((E/rou)*(1/four[9]));
  255.         omega=omega*xz;
  256.         printf("二阶固有静频为:%.5fHZ\n",omega/(2*3.1415926));

  257.         //第三个函数开始
  258.         float Y3js[10]={0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1};
  259.         float Y3[10]={0,0,0,0,0,0,0,0,0,0};
  260.         float Y3sj[10]={0,0,0,0,0,0,0,0,0,0};

  261.         b11=0;
  262.         float b12=0;
  263.         float b21=0;
  264.         float b22=0;
  265.         float C31=0;
  266.         float C32=0;
  267.         float a31=0;
  268.         float a32=0;
  269.         a32=10;
  270.         float shoulian=10;

  271.         while(shoulian>=0.0001)                  //给定拟合精确度
  272.         {       
  273.                 while(i<=9)
  274.                   {
  275.                         Y3js[i]=Y3[i];
  276.                         i++;
  277.                   }
  278.        
  279.             b12=0;
  280.             b21=0;
  281.             b22=0;
  282.             C31=0;
  283.             C32=0;
  284.             a31=0;
  285.             a32=0;
  286.                
  287.                 i=0;
  288.                 while(i<=9)
  289.                   {
  290.                         b11=b11+2850*Ab[i]*Y0xxx[i]*Y0xxx[i]*0.01;
  291.                         i++;
  292.                   }
  293.                
  294.                 i=0;
  295.                 while(i<=9)
  296.                   {
  297.                         b12=b12+2850*Ab[i]*Y0xxx[i]*Y2[i]*0.01;
  298.                         i++;
  299.                   }

  300.                 i=0;
  301.                 while(i<=9)
  302.                 {
  303.                         b21=b21+2850*Ab[i]*Y0xxx[i]*Y2[i]*0.01;
  304.                         i++;
  305.                 }  

  306.                 i=0;
  307.                 while(i<=9)
  308.                 {
  309.                         b22=b22+2850*Ab[i]*Y2[b]*Y2[i]*0.01;
  310.                         i++;
  311.                   }   

  312.                 i=0;
  313.                 while(i<=9)
  314.                   {
  315.                         C31=C31+2850*Ab[i]*Y0xxx[i]*Y3js[i]*0.01;
  316.                         i++;
  317.                 }

  318.                 i=0;
  319.                 while(i<=9)
  320.                 {
  321.                         C32=C32+2850*Ab[i]*Y2[i]*Y3js[i]*0.01;
  322.                         i++;
  323.                   }
  324.                
  325.                 a31=C31/b11;  
  326.                 a32=C32/b22;   
  327.                
  328.                 i=0;
  329.                 while(i<=9)
  330.                 {
  331.                         Y3[i]=Y3js[i]-a31*Y0xxx[i]-a32*Y2[i];
  332.                         i++;
  333.                 }
  334.                  
  335.                   shoulian=fabs(Y3js[0]-Y3[0]);
  336.         }

  337.     q=0;
  338.            while(9>=q)
  339.     {
  340.         one[q]=0;
  341.         two[q]=0;
  342.         three[q]=0;
  343.         four[q]=0;
  344.         q=q+1;
  345.     }                             //这步是给数组清零,千万不能忘!
  346.    
  347.         a=0;
  348.     b=0;
  349.     while(9>=a)
  350.     {
  351.               b=a;
  352.               while(9>=b+2)
  353.         {
  354.                   one[a]=one[a]+(Ab[b+2]*Y3[b+2]*0.01);
  355.                   b=b+1;
  356.         }
  357.         a=a+1;
  358.     }                                 //第一重循环

  359.     c=0;
  360.     d=0;
  361.     while(9>=c)
  362.     {
  363.               d=c;
  364.               while(9>=d+1)
  365.         {
  366.                   two[c]=two[c]+(one[d+1]*0.01);
  367.                   d=d+1;
  368.         }
  369.         c=c+1;
  370.     }                                 //第二重循环
  371.   
  372.     e=0;
  373.     f=0;
  374.     while(9>=e)
  375.     {
  376.               f=0;
  377.               while(e>=f)
  378.         {
  379.                   three[e]=three[e]+two[f]*0.01*(1/Ib[f]);
  380.                   f=f+1;
  381.         }
  382.         e=e+1;
  383.         }                                 //第三重循环  
  384.    
  385.     g=0;
  386.     h=0;
  387.     while(9>=g)
  388.     {
  389.               h=0;
  390.               while(g>=h)
  391.         {
  392.                  four[g]=four[g]+three[h]*0.01;
  393.                  h=h+1;
  394.         }
  395.         g=g+1;
  396.         }                                 //第四重循环
  397.    
  398.         omega=sqrt((E/rou)*(1/four[9]));
  399.         omega=omega*xz;
  400.         omega=sqrt((E/rou)*(1/four[9]));
  401.         omega=omega*xiuzhen;
  402.         printf("三阶固有静频为:%.5fHZ\n",(2*omega)/(2*3.1415926));
  403.         system("pause");
  404. }
复制代码


问题描述:两个程序第一个函数和第二个函数产生数据相同,第三个函数从变量b12开始计算有误。结算结果两者相差1e9。
最佳答案
2020-4-15 23:09:10
本帖最后由 耻思lhj 于 2020-4-15 23:33 编辑

所以你python的答案是什么?
我把你所有的float改成了double,因为我认为可能是精度的问题,下面是改了后c运行的结果
一阶固有静频为:406.98650HZ
二阶固有静频为:1795.49790HZ
三阶固有静频为:4594.51734HZ
都改为double:第九次循环b12=-4e-019
没改之前float:第九次循环b12=3e-010

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

 楼主| 发表于 2020-4-15 22:22:39 | 显示全部楼层
续帖:
与b12有关的数组:Ab,Y2,Y0xxx三组数值相同
  1. python数组
  2. Y2 = array([-0.00915524,
  3. -0.12828047,
  4. -0.3583434 ,
  5. -0.59971634,
  6. -0.55154928,
  7. -0.41236732,
  8. -0.37925495,
  9. 0.15134434,  
  10. 0.38194363,
  11. 0.51254293])

  12. Y0xxx =
  13. array([0.07180484,
  14. 0.22180461,
  15. 0.45758906,
  16. 0.78207828,
  17. 1.1886056 ,
  18. 1.66560334,
  19. 2.19020504,
  20. 2.73451689,
  21. 3.27882874,
  22. 3.82314059])

  23. Ab=
  24. array([1.580e-04,
  25. 1.360e-04,
  26. 1.175e-04,
  27. 1.025e-04,
  28. 9.100e-05,
  29. 8.150e-05,
  30. 7.500e-05,
  31. 7.150e-05,
  32. 6.900e-05,
  33. 6.800e-05])
复制代码

  1. C数组
  2. Ab =
  3. {0.00015800001,
  4. 0.000136000002,
  5. 0.0001175,
  6. 0.000102500002,
  7. 9.10000017e-005,
  8. 8.14999948e-005,
  9. 7.50000036e-005,
  10. 7.1500006e-005,
  11. 6.90000015e-005,
  12. 6.80000012e-005}

  13. Y0xxx =
  14. {0.0718048364,
  15. 0.221804589,
  16. 0.45758903,
  17. 0.782078266,
  18. 1.18860555,
  19. 1.66560328,
  20. 2.1902051,
  21. 2.73451686,
  22. 3.27882862,
  23. 3.82314038}

  24. Y2 =
  25. {-0.00915524177,
  26. -0.128280476,
  27. -0.358343422,
  28. -0.599716365,
  29. -0.551549315,
  30. -0.412367314,
  31. -0.379254967,
  32. 0.151344314,
  33. 0.381943643,
  34. 0.512542963}
复制代码


在执行循环时,前八次循环b12值相同,然而第九次循环结束后,两个代码b12的值就相差1e9,目前不知道为何,希望鱼C论坛的大佬们能够帮助我,比较着急,跪谢!
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2020-4-15 23:09:10 | 显示全部楼层    本楼为最佳答案   
本帖最后由 耻思lhj 于 2020-4-15 23:33 编辑

所以你python的答案是什么?
我把你所有的float改成了double,因为我认为可能是精度的问题,下面是改了后c运行的结果
一阶固有静频为:406.98650HZ
二阶固有静频为:1795.49790HZ
三阶固有静频为:4594.51734HZ
都改为double:第九次循环b12=-4e-019
没改之前float:第九次循环b12=3e-010

小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 1 反对 0

使用道具 举报

 楼主| 发表于 2020-4-16 07:44:54 | 显示全部楼层
耻思lhj 发表于 2020-4-15 23:09
所以你python的答案是什么?
我把你所有的float改成了double,因为我认为可能是精度的问题,下面是改了后c ...

谢谢带佬,原来是float和double的问题!
我这个python程序可能还有点问题,我再去看看。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-6-17 07:38

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表