科学网

 找回密码
  注册

tag 标签: double

相关帖子

版块 作者 回复/查看 最后发表

没有相关内容

相关日志

C语言中如何从文本文件中读写double类型的数据
Geophoenix 2015-12-2 12:24
double类型的数据读写在一般的C语言编程书籍很少提及,不知道这是认为大伙都知道还是咋的。这里记录一下,以备后用。 File *fp; double dat; //从文本中读入一个double类型的数据 fscanf(fp,%lf,dat); //%lf是表示的double类型的数据 //向文本文件中写入一个double类型的数据 fprintf(fp,%lf,dat); //至于从二进制文件中读写就容易的多了,俺是比较喜欢二进制数据,规整:) //从二进制文件中读入一个double类型的数据 fread(dat,sizeof(double),1,fp); //向二进制文件中写入一个double类型的数据 fwrite(dat,sizeof(double),1,fp);
个人分类: 编程|8972 次阅读|0 个评论
痛心呀!(为反对“全球变暖”的人士提供了炮弹)
zuojun 2015-10-2 07:21
http://wattsupwiththat.com/2015/09/30/rico20-4-million-nsf-grant-while-shuklas-organization-is-being-dissolved/ ps. I visited the center recently, to lecture on scientific writing. I was not a part of the center, but could have been (because I was asked to join by my first boss). pps. It's not a good idea to hire your daughters to run a company, even if it's a not-for-profit one.
个人分类: My Research Interests|2585 次阅读|0 个评论
[转载]Jamaican Relay double
whyhoo 2013-8-19 10:32
Sunday evening saw the last session of competition at Luzhniki Stadium in Moscow, wrapping up the 2013 IAAF World Championships. Usain Bolt capped the competition with another scorching performance, running away from the 4x100m Relay field to give Jamaica gold for the third consecutive championships and secure a relay double for Jamaica, who also won the women’s race. Titles were also decided in the women’s 800m, men’s 1500m, and on the field, the men’s Triple Jump and the women’s Javelin Throw. Bolt blasts anchor leg The shorter relay was a wild affair with several teams in contention up to the last exchange. There, at the top of the homestretch, Bolt got the baton from Nickel Ashmeade more or less equal with the USA quartet. Bolt then simply left Justin Gatlin in his wake, opening a gap immediately and bringing the Jamaican squad home in 37.36 to the USA’s 37.66. Crossing the line third was the team from Great Britain, then Canada in 37.92. However, Great Britain were disqualified for passing the baton outside the second exchange zone, and Canada wound up in bronze position. Jamaican relay double Bolt’s successful anchor leg, while impressive, was equalled in its dominance by the performance of the women’s team. The quartet of Carrie Russell, Kerron Stewart, Schillonie Calvert, and double sprint champion Shelly-Ann Fraser-Pryce set a championship and national record of 41.29 by handing Fraser-Pryce the baton with a sizeable lead and pointing the “Pocket Rocket” at the finish line. Behind them was some confusion. France crossed the line next and was in silver medal position as of the medal ceremony, where they were given the medals for their 42.73 finish. The USA, which struggled through the second exchange but recovered quickly to finish in 42.75, were given bronze. However, a late protest reopened the results, and France was disqualified under rule 170.7, which pertains to exchanging the baton within the exchange zone. As a result, the USA team was elevated to silver, and bronze went to Great Britain, who had finished in 42.87. Sum victory in 800m Defending champion Marya Savinova was, understandably, the crowd favourite in the women’s 800m final, and as she moved to pass early leader Alysia Johnson Montano, they roared their approval. Savinova, however, had just started on her frantic, and ultimately unsuccessful, sprint to catch Eunice Sum. The Kenyan had moved earliest to catch the fast-starting Montano, and as a result built a lead over Savinova that the Russian was unable to close. Sum won gold in 1:57.38, with Savinova in silver (1:57.80) and a hard-charging Brenda Martinez of the USA in bronze (1:57.91). Johnson Montano tumbled to the track fourth in 1:57.95. Kiprop unbeatable Asbel Kiprop dominated the men’s 1500m final in much the same way that Mo Farah dominated the longer races, controlling the pace throughout and setting up his own victory. The defending champion (and 2008 Olympic champion), still only 24, dictated a slow pace at first, held the pack back from pursuing team-mate Nixon Chepseba, and finally launched an unbeatable drive to the finish which brought him to the line in 3:36.28. Behind him, Daegu bronze medallist Matt Centrowitz improved to silver with a 3:36.78; the surprise of the race was Johan Cronje of South Africa in third with 3:36.83. Tamgho transcendent The men’s Triple Jump was, improbably, tied going in to the last round, with both Teddy Tamgho and Cuba’s Pedro Pechardo at 17.68m. The tie would have been decided in Tamgho’s favour due to his better second jump (17.65m) but after a series of fouls which saw him very far out in the pit, he sprung out to 18.04m in the sixth and last round. It would be the only effort over 18 metres of the competition. Pechardo, forced to respond with only his last remaining attempt, was unable, and the Frenchman took the title. Behind Tamgho and Pechardo came USA’s Will Claye with a 17.52m mark. Defending World champion and Olympic champion Christian Taylor came fourth, only able to manage 17.20m. Obergfoll over all Maria Abakumova was the competitive favourite and the crowd favourite for the women’s Javelin Throw, but in the end she was one of the few Russians to under-perform expectations, managing only 65.09m, well off her best this year and exactly four metres shy of her qualifying throw. Christina Obergfoll, on the other hand, was masterful, reaching 69.05m in the fifth round, good enough to win by more than two meters. The surprise of the night was Australia’s Kimberly Mickle, who capitalized on Abakumova’s lack of form with a 66.60m PB, good enough to earn her silver. Like her husband Dmitri Tarabin, Abakumova had to settle for bronze. Parker Morse for the IAAF 原文见 http://www.iaaf.org/competitions/iaaf-world-championships/news/jamaican-relay-double-day-9-wrap-moscow-201
个人分类: 奥运会|1448 次阅读|0 个评论
[转载]java输出整数,double,字符串等到一个文件中
aaa0 2013-5-28 05:38
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.Vector; public class ListOfNumbersDeclared { public static void main(String[] a) { Vector victor; int size = 10; victor = new Vector(size); for ( int i = 0; i size; i++) victor.addElement( new Integer(i)); try { PrintStream out = new PrintStream( new FileOutputStream( OutFile.txt)); for ( int i = 0; i size; i++) out.println(Value at: + i + = + victor.elementAt(i)); out.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } } }
2733 次阅读|0 个评论
[转载]Angelina Jolie reveals she recently underwent a double maste
chnfirst 2013-5-14 23:58
http://wonderwall.msn.com/movies/angelina-jolie-reveals-double-mastectomy-in-ny-times-op-ed-piece-24886.gallery Angelina Jolie reveals she recently underwent a double mastectomy Photo: KH1/WENN 1 of 25 In a jaw-dropping and moving op-ed in the New York Times , Angelina Jolie has revealed she recently underwent a double mastectomy after testing positive for the gene that predisposes her to breast and ovarian cancer. My mother fought cancer for almost a decade and died at 56, writes the 37-year-old Oscar winner and U.N. goodwill ambassador. She held out long enough to meet the first of her grandchildren and to hold them in her arms. ... We often speak of 'Mommy's mommy,' and I find myself trying to explain the illness that took her away from us. They have asked if the same could happen to me. I have always told them not to worry, but the truth is I carry a 'faulty' gene, BRCA1, which sharply increases my risk of developing breast cancer and ovarian cancer. She acknowledges that the odds were not in her favor: My doctors estimated that I had an 87 percent risk of breast cancer and a 50 percent risk of ovarian cancer, although the risk is different in the case of each woman. According to Jolie, Once I knew that this was my reality, I decided to be proactive and to minimize the risk as much I could. I made a decision to have a preventive double mastectomy. I started with the breasts, as my risk of breast cancer is higher than my risk of ovarian cancer, and the surgery is more complex. On April 27, she completed three months of medical procedures that the mastectomies involved. During that time I have been able to keep this private and to carry on with my work. But she's writing about it now because I hope that other women can benefit from my experience, she explains. Cancer is still a word that strikes fear into people's hearts, producing a deep sense of powerlessness. But today it is possible to find out through a blood test whether you are highly susceptible to breast and ovarian cancer, and then take action. Jolie goes on to describe her surgeries, her reasons for going public and the loving support she's received from Brad Pitt . Read on for more of her gut-wrenching decision
个人分类: 学习、语言|0 个评论
[转载]matlab用法
yuaihua 2013-3-7 16:39
int转string:int2str(m) double转string:num2str(m) 在matlanb中help uint8,就可以看到matlab中常用的数据类型,如double, single, datatypes, isinteger, uint16, uint32, uint64, int8, int16, int32, int64,等,至于每种数据类型在计算机中占几个字节,精度高的向精度低的转换会丢失哪些信息则没有仔细研究。如果部考虑信息损失问题,类型转换就比较 简单了。假如现在有一double型的变量i要转换成uint8型,则只需i=uint8(i)就行了。datatypes没去研究过,应当跟一般的数值 类型有所区别,其它的数值类型就以此类推,v=datatype(v)。 读取图像:用imread函数读取图像文件,文件格式可以是TIFF、JPEG、GIF、BMP、PNG等。比如       f = imread('chestxray.jpg');   读进来的图像数据被保存在变量f中。尾部的分号用来抑制输出。如果图片是彩色的,可以用rgb2gray转换成灰度图:       f = rgb2gray(f);   然后可以用size函数看图像的大小       size(f)   如果f是灰度图像,则可以用下面的命令把这个图像的大小赋给变量M和N       = size(f);   用whos命令查看变量的属性       whos f   显示图像:用imshow显示图像      imshow(f, G)   其中f是图像矩阵,G是像素的灰度级,G可以省略。比如       imshow(f, )   图像上所有小于等于100的数值都会显示成黑色,所有大于等于200的数值都会显示成白色。pixval命令可以用来查看图像上光标所指位置的像素值。      pixval   例如       f = imread('rose_512.tif');    whos f    imshow(f)   如果要同时显示两幅图像,可以用figure命令,比如       figure, imshow(g)   用逗号可以分割一行中的多个命令。imshow的第二个参数用一个空的中括号:       imshow(h,    D = uint8(C)   图像类型分为:      Intensity image 灰度图   Binary image 二值图   Indexed image 索引图   RGB image 彩色图   在灰度图中每个像素可以是整型、浮点型或者逻辑型。图像类型的像素类型可以转换      function to from   im2uint8 uint8 logical,uint8,uint16,double   im2uint16 uint16 logical,uint8,uint16,double   mat2gray double double   im2double double logical,uint8,uint16,double   im2bw logical uint8,uint16,double   比如      g = mat2gray(A, );   g = mat2gray(A);   g = im2double(h);   g = im2bw(f, T)   其中A是浮点型的图像,Amin和Amax是浮点数的范围,h和f是任意类型的图像,T是分割的阈值。   数组(向量)索引:创建向量(数组):       v =   用小括号对向量进行索引(取数组中的某个元素):       v(2)   转置(将行向量通过转置变成列向量):       w = v.'   取向量其中的一部分:       v(1:3) 第1个到第3个    v(2:4)    v(3:end) 第3个到最后一个    v(1:end)    v(:) 全部    v(1:2:end) 第1个到最后一个,每次增加2    v(end:-2:1) 最后一个到第1个,每次减2   其中end总是表示最后一个。       x = linspace(1, 5, 10)    v( )   linspace函数产生一个范围内的平均分布。   矩阵索引:创建矩阵       A =   取矩阵中的一个元素       A(2, 3)   取矩阵中的一行或者一列       C3 = A(:, 3)    R2 = A(2, :)   取矩阵中某些行某些列       T2 = A(1:2, 1:3)   对矩阵中某些元素进行赋值:       B = A;    B(:, 3) = 0   用end表示最后一行或者最后一列:       A(end, end) 最后一行最后一列    A(end, end-2) 最后一行倒数第三列    A(2:end, end:-2:1) 第2行到最后一行,最后一列到第一列,每次减2    E = A( , ) 第1、3行,第2、3列    D = logical( )    A(D) 取A中由D指定的位置上的元素    v = T2(:) 把矩阵变成一个向量    s = sum(A(:)) 求和    sum(sum(A))   可以把矩阵操作用在图像上       f = imread('filename');    fp = 矩阵列倒转    imshow(fp)    fc =    imshow(fc)    fs =    imshow(fs)    plot(f(512,:))   矩阵可以是多维的,用size看矩阵大小,用ndims命令常看矩阵的维数       size(A, 1)    ndims(A)   一些常用的矩阵      zeroes(M, N)   ones(M, N)   true(M, N)   false(M, N)   magic(M)   rand(M, N)   randn(M, N)   其中M、N表示矩阵的行数和列数。比如       A = 5 * ones(3, 3)    magic(3)    B = rand(2, 4)   函数:可以把一系列的MATLAB语句或者一个带参数的函数放在扩展名叫做m的文件中。一个带函数的m文件有一下部分组成      函数定义行   H1行   帮助部分   函数体   注释   函数定义行的格式是      function = name(inputs)   比如要写一个函数计算两个图像的和以及乘积      function = sumprod(f, g)   其中f和g是输入的图像,而s是和,p是乘积。返回值用中括号括起来,如果返回值只有一个,可以省略中括号。如果函数没有输出,则中括号和等号都可以省略。函数名字的命名规则和C语言是相同的。定义好的函数可以在命令行调用:       = sumprod(f, g);   也可以被其它函数调用。如果只有一个返回值,调用时中括号也是可以省略的,比如       y = sum(x);   H1行是文本的第一行,是一个单行的注释,紧跟在函数定义行后面,之间不能有空行。比如      % SUMPROD Computes the sum and product of two images.   百分号开始的文字表示注释。当使用帮助命令       help function_name   时,这个H1行会被首先显示出来。如果使用lookfor命令,则会在所有H1行中查找指定的关键字。这一行应该提供这个函数功能的一个概述。帮助部分是紧跟在H1后的文本块,中间没有空行,用来提供对这个函数更详细的帮助说明。在使用help命令时会显示所有这部分内容。这部分内容由注释语句构成,全部由%开始。接下来第一个非注释语句表示函数体的开始。函数体包含进行计算的语句和给返回值赋值的语句。函数题中的所有注释(百分号开始的行)被认为是普通的注释,不是H1或者帮助部分。m文件可以用任何文本编辑器创建和编辑,只要用.m扩展名保存在MATLAB可以搜索到的路径里面。另一个创建和编辑函数的方法是在命令行输入edit命令,比如       edit sumprod   这命令会编辑已经存在的sumprod.m文件,如果没有则自动在当前目录中创建一个sumprod.m并开始编辑。   运算符。运算符可以分为算术运算符,关系运算符和逻辑运算符。算术运算符分为矩阵算术运算符和数组算术运算符。      + 矩阵和数组加法 plus(A, B) a+b, A+B   - 矩阵和数组减法 minus(A,B) a-b, A-B   .* 数组乘法 times(A,B) C=A.*B, 意味着C(I,J) = A(I,J)*B(I,J)   * 矩阵乘法 mtimes(A,B) A*B, 表示线性代数中的矩阵运算,或者a*A   ./ 数组右除 rdivide(A,B) C=A./B, 意味着C(I,J)=A(I,J)/B(I,J)   .\ 数组左除 ldivide(A,B) C=A.\B, 意味着C(I,J)=B(I,J)/A(I,J)   / 矩阵右除 mrdivide(A,B) A/B 意味着A*inv(B), inv是矩阵求逆   \ 矩阵左除 mldivide(A,B) A\B 意味着inv(A)*B   .^ 数组指数 power(A, B) C=A.^B,意味着C(I,J)=A(I,J)^B(I,J)   ^ 矩阵指数 mpower(A,B) 请查看帮助   .' 向量和矩阵转置 transpose(A) A.'   ' 复数的共轭 ctranspose(A) A'   + 单目加号 uplus(A) +A 与0+A相同   - 单目负号 uminus(A) -A 与0-A相同   图像处理工具包还提供其他一些算术运算      imadd 两个图像相加,或者一个图像加上一个常量   imsubstract 两个图像相减,或者一个图像减掉一个常量   immultiply 两个图像相乘,或者一个图像乘上一个常量   imdivide 两个图像相除,或者一个图像除以一个常量   imabsdiff 两个图像的差的绝对值   imcomplement 求一个图像的反色图   inlincomb 求一组图像的线性组合   关系运算符包括         =      =   ==   ~=   关系运算符的结果是逻辑型的矩阵,比如       A =    B =    A == B    A = B   如果关系运算符两边都是矩阵,则要求两边的矩阵是同样大小的。或者一边是矩阵一边是常数,或者两边都是常数,那也是可以。       A 3    3 ~= 4   逻辑运算符包括与、或、非三个运算       AND   | OR   ~ NOT   在matlab中非0被认为是真,0被认为是假。比如      A =   B =    A B   MATLAB还有其它一些逻辑运算函数:      xor 异或   all 如果一整列都是真,则结果是真   any 如果一整列只要有一个是真,则结果是真   比如       xor(A, B)    all(A)    any(A)    all(B)    any(B)   一些重要的常量      ans   eps   i(或者j)   NaN或者nan   pi   realmax   realmin   computer   version   MATLAB中一般常量的写法      3   -99   0.00001   9.6397238   1.60210e-20   6.02252e23   1i   -3.14159j   3e5j   控制流。包括      if if和else, elseif组合,条件执行一组语句   for 指定次数重复执行一组语句   while 按条件反复执行一组语句   break 终止for或者while循环   continue 马上开始下一次for或者while循环   switch switch和case,otherwise结合,按照条件值的不同执行不同的语句块   return 终止当前函数,返回到调用它的地方   try...catch 捕获异常状况   if语句      if expression_r1   statements1   elseif expression_r2   statements2   else   statements3   end   for循环      for index = start:increment:end   statements   end   比如      count = 0;   for k = 0:0.1:1   count = count +1   end   while循环      while expression_r   statements   end   比如      a = 10;   b = 5;   while a   a = a - 1;   while b    b = b - 1;   end   end   switch语句      switch switch_expression_r   case case_expression_r    statements   case {case_expression_r1, case_expression_r2}    statements   otherwise    statements   end   比如      switch newclass   case 'uint8'    g = im2uint8(f);   case 'uint16'    g = im2uint16(f);   case 'double'    g = im2double(f);   otherwise    error('Unknown or improper image class.')   end   例子:写一个函数计算一幅灰度图像所有像素的平均值      function av = average(A)   %AVERAGE Computes the average value of an array   % AV = AVERAGE(A) computes the average value of input array, A,   % which must be a 1D or 2D array.      % Check the validity of input.   if ndims(A) 2   error('The dimensions of the input cannot exceed 2.')   end   % Computes the average   av =   例子:比较各种不同的JPEG质量下的图像质量      for q = 0:5:100   filename = sprintf('series_%3d.jpg', q);   imwrite(f, filename, 'quality', q);   end   其中sprintf语句和c语言的fprintf语句用法类似。例子:写一个函数从一个图像中取出一个矩形的子图。      function s = subdim(f, m, n, rx, cy)   %SUBDIM Extracts a subimage, s, from a given image, f.   % The subimage is of size m-by-n, and the coordinates of its top, left   % corner are (rx, cy).      s = zeros(m, n);   rowhigh = rx + m - 1;   colhigh = cy + n - 1;   xcount = 0;   for r = rx:rowhigh   xcount = xcount + 1;   ycount = 0;   for c = cy:colhigh    ycount = ycount + 1;    s(xcount, ycount) = f(r, c);   end   end   实际上这个功能可以用一个matlab语句就可以实现了。   循环优化。一些循环可以被转换成同样向量计算来代替,比如f(x)=Asin(x/2pi),生成一个向量包含一组函数的值:      for x = 1:M   f(x) = A*sin((x-1)/(2*pi));   end   可以用下面两个语句来代替      x =   f = A*sin(x/2(*pi))   向量运算要比循环快得多。对于二维的情况,MATLAB提供了一个meshgrid函数       = meshgrid(c, r)   比如       r = ;    c = ;    = meshgrid(c, r)    h = R.^2 + C.^2   例子:f(x, y) = Asin(ux + vy),生成一个矩阵,包含这个函数的值:      function = twodsin(A, u0, v0, M, N)   %TWODSIN compare for loops vs vectorization   % The comparision is based on implementing the function   % f(x, y) = Asin(u0x+v0y) for x = 0, 1, 2,..., M-1, and   % y = 0, 1, 2, ..., N-1. The inputs to the function are   % M and N and the constants in the function.      tic   for r = 1:M   u0x = u0*(r-1);   for c = 1:N    v0y = v0*(c-1)    f(r, c) = A*sin(u0x + v0y);   end   end   t1 = toc;      tic   r =   c =    = meshgrid(c, r);   g = A*sin(u0*R + v0*C)   t2 = toc;      rt = t1/t2;   运行这个例子可以看出,向量计算至少比循环要快30倍。如果只是针对图像的一部分进行操作,可以简单的提取出来,比如      rowhigh = rx + m - 1;   colhigh = cy + n - 1;   s =   同样功能的程序,这个写法比前面例子看到的写法要快1000倍。   用户交互。函数disp用来提示用户一些信息。比如       A = ;    disp(A)    sc = 'Digital Image Processing.';    disp(sc)    disp('This is another way to display text.')   input函数用来提示用户输入某些值:      t = input('message')   这个函数可以显示message,并等待用户输入一个值,并存到t中。输入的值可以是MATLAB允许的任何类型的值。而如下的格式只接受字符串输入      t = input('message', 's')   如果字符串中包含的都是数字,则可以用函数str2num进行转换      n = str2num(t)   比如       t = input('Enter your data: ', 's')    class(t)    size(t)    n = str2num(t)    size(n)    class(n)   如果混合输入字符串和数值,可以全部按照字符串读入,再使用字符串处理函数strread,比如:       t = '12.6, x2y, z';    = strread(t, '%f%q%q', 'delimiter', ',')    d = char(b)   其中%f表示浮点数,%q表示字符串。delimiter参数表示分割符。函数strcmp用来比较字符串,如果两个字符串相等返回真,否则返回假。lower函数可以把字符串中的大写字母全部变成小写,upper函数可以把字符串中所有小写字母全部变成大写。   Cell数组和结构体。Cell数组是指数组的元素本身还是一个数组,比如       c = {'gause', , 3}    c{1}    c{2}    c{3}   结构体和Cell数组类似,但是其中的元素是用一个名字去访问的,比如       S.char_string = 'gause';    S.matrix = ;    S.scalar = 3;    S.matrix      实验任务   MATLAB 没有提供一个函数来确定数组的每个元素是不是整数(即...,-2,-1,0,1,2,...)。写一个函数来实现这个功能,并满足下面的格式:      function I = isinteger(A)   %ISINTEGER Determines which elements of an array are integers.   % I = ISINTEGER(A) returns a logical array, I, of the same size   % as A, with 1s (TRUE) in the locations corresponding to integers   % (i.e., . . . -2 -1 0 1 2 . . . )in A, and 0s (FALSE) elsewhere.   % A must be a numeric array.   要求不能使用while或者for循环。提示:使用floor函数。如果你要做到能够处理复数,那么可以使用real和imag函数。   MATLAB没有提供一个函数用来确定数组的每个元素是不是偶数(即...,-4,-2,0,2,4,...)。写一个函数来实现这个功能,并满足下面的格式:      function E = iseven(A)   %ISEVEN Determines which elements of an array are even numbers.   % E = ISEVEN(A) returns a logical array, E, of the same size as A,   % with 1s (TRUE) in the locations corresponding to even numbers   % (i.e., . . . -3, -1, 0, 2, 4, . . . )in A, and 0s (FALSE) elsewhere.   % A must be a numeric array.   要求不能使用while或者for循环。提示:使用floor函数。   MATLAB没有提供一个函数用来确定数组的每个元素是不是奇数(即...,?3,?1,1,3,...)。写一个函数实现这个功能,并满足下面的格式:      function D = isodd(A)   %ISODD Determines which elements of an array are odd numbers.   % E = ISODD(A) returns a logical array, D, of the same size as A,   % with 1s (TRUE) in the locations corresponding to odd numbers   % (i.e., . . . -3, -1, 1, 3, . . . )in A, and 0s (FALSE) elsewhere.   % A must be a numeric array.   要求不能使用while或者for循环。提示:使用floor函数。   写一个函数满足下面的规定:      function H = imcircle(R, M, N)   %IMCIRCLE Generates a circle inside a rectangle.   % H = IMCIRCLE(R, M, N) generates a circle of radius R centered   % on a rectangle of height M and width N. H is a binary image with   % 1s on the circle and 0s elsewhere. R must be an integer = 1.   你的程序应该检查R的合理性,使它能够在矩形的内部。要求不能使用for或者while循环。提示:使用函数meshgrid和floor函数。   这个实验主要目的是学习如何显示和改变目录,并利用目录信息来读取图像。写一个函数满足下面的规定:      function = imagein(path)   %IMAGEIN Read image in from current-working or specified directory.   % I = IMAGEIN displays a window containing all the files in the   % current directory, and saves in I the image selected from the   % current directory.   % = IMAGEIN variable MAP is required to be an output   % argument when the image being read is an indexed image.   % = IMAGEIN('PATH') is used when the image to be read   % resides in a specified directory. For example, the input   % argument 'C:\MY_WORK\MY_IMAGES' opens a window showing   % the contents of directory MY_IMAGES. An image selected from   % that directory is read in as image I.   提示:使用在线帮助来熟悉cd,pwd,uigetfile函数的使用。或者也可以采用fullfile函数来代替cd函数
8149 次阅读|0 个评论
赤经赤纬的字符串格式转化为双精度格式IDL程序
deliangwang 2013-1-29 22:21
Function radec_str2dbl, string_input, select ;+ ;NAME: ; radec_str2dbl ;PURPOSE: ; transform string to double for RA or DEC ;CALLING SEQUENCE: ; rah=radec_str2dbl(ra) ;EXAMPLE: ; IDL ra='00 06 23.0' ; IDL rah=radec_str2dbl(ra,0) ; IDL print,rah ; 0.10638889 ;INPUT: ; string_input --- Right ascension (J2000) ; select ---- 0: blank space separated ; 1: hms separated ; 2: dms separated ; 3: : separated ;OUTPUT: ; outdata ;REVISION HISTORY: ; Original by DL.Wang,30-Dec-2008 ;- if n_elements(select) eq 0 then begin print,'Please select the format input string' print,'0: blank space separated' print,'1: hms separated' print,'2: dms separated' print,'3: : separated' stop endif n=n_elements(string_input) x=strarr(n,3) case select of 0:begin for i=0L,n-1 do begin x =strsplit(string_input ,'( )',/extract) endfor end 1:begin for i=0L,n-1 do begin x =strsplit(string_input ,'(h)(m)(s)( )',/extract) endfor end 2:begin for i=0L,n-1 do begin x =strsplit(string_input ,'(d)(m)(s)( )',/extract) endfor end 3:begin for i=0L,n-1 do begin x =strsplit(string_input ,'(:)( )',/extract) endfor end endcase hd=double(x ) mm=double(x ) ss=double(x ) outdata=tenv(hd,mm,ss) return,double(outdata) End
4184 次阅读|0 个评论
[转载]The double happiness
michenggang 2013-1-20 10:49
People who analyze algorithms have double happiness. First of all they experience the sheer beauty of elegant mathematical patterns that surround elegant computational procedures. Then they receive a practical payoff when their theories make it possible to get other jobs done more quickly and more economically. –Donald Knuth
个人分类: 科研心得|1879 次阅读|0 个评论
[转载]2012年度(第十届)中国法经济学论坛会议日程安排
热度 1 freedom110110 2012-6-18 22:06
论坛日程安排 6 月 22 日下午 论坛报到 13:00-22:00 报到注册 地点:重庆奥蓝酒店 地址:重庆市渝北区双龙大道 218 号 电话: 联系人 : 陈屹立 雷国雄 电话 : 13508383975 ; 15223378931 18:00-20:00 晚餐 自助点餐(凭代表证和餐券就餐) 地点:奥蓝酒店 联系人 : 唐潜宁 电话 : 13983246992 20:00-22:00 自由活动 6 月 23 日、 24 日早餐 7:30— 8:30 自助餐 地点:奥蓝酒店(凭代表证和餐券就餐) 6 月 23 日上午 开幕式暨主题演讲 ( 地点:奥蓝酒店学术报告厅 ) 8:30-8:50 开幕式 主 持 人:史晋川 浙江大学社会科学学部主任、经济学院院长 嘉宾致辞: 张国林 西南政法大学党委书记 黄少安 山东大学经济研究院(中心) 王 诚 《经济研究》编辑部 8:50- 9 : 00 代表合影 地点: 奥蓝酒店大堂外广场 9:00- 10:30 主题报告一 (第一阶段) 主持人:李树 西南政法大学经济学院院长 演讲嘉宾: 熊秉元(台湾大学经济系、浙江大学永谦讲座教授):公地、逆式公地和两者之间 黄少安(山东大学经济研究院):“租税替代”、财政收入与政府的房地产政策 魏 建、王安(山东大学经济研究院):地方政治结构与经济增长方式调整 注:每一主题发言时间 30 分钟。 10:30-10:40 茶歇 10:40- 12:00 主题报告二 (第二阶段) 主持人: 魏 建 山东大学经济研究院(中心) 演讲嘉宾: 李 树(西南政法大学经济学院):环境管制与生产率增长: 以 APPCL2000 的修订为例 胡伟强( Erasmus University Rotterdam ):反思《侵权责任法》第 35 条第 1 款之规定——从法律经济学分析的视角解读 周林彬、孙琳玲(中山大学法学院):法律规避的法律经济学新探:以公司融资中的法律规避为例 史晋川、王 婷(浙江大学经济学院):社会网络与非正式金融制度 注:每一主题发言时间 20 分钟。 12:00 中餐 地点:奥蓝酒店 自助餐厅(凭代表证和餐券就餐) 6 月 23 日下午论坛分组报告 (注:报告人发言时间为 10-15 分钟,讨论时间为 5 - 10 分钟) (一) 主题一讨论日程安排 小组主题:理论与历史 分组地点: 奥蓝酒店会议室 1 主持人: 雷国雄 ( 14:00 - 15:30 ) 报告人及题目 王 鹏:信息不对称条件下法院判决正确性问题探析 田钒平:制度结构研究范式的理论反思与回归 王 瑞:制度内生的一个经济增长模型 姚小林:地方立法项目供给效果分析 时 晋、曾 斌、吴锦宇:中国大陆发审委的法经济学反思 茶歇( 15 : 30 - 15 : 40 ) 主持人: 田钒平 ( 15:40 - 17:10 ) 雷国雄:制度的博弈论解释批判 李启航:法律对财产性收入作用的城乡差异 李亚凝:以 Netlogo 社会模拟实验为基础对道德缺失的解决方案 宁静波:法院的“产出”效率问题分析 17:15- 18:30 乘车前往沙坪坝区瓷器口古镇钟府私家菜 ( 中途参观西南政法大学校园 ) 18:30- 19:30 晚宴 19:30- 20:30 参观瓷器口古镇 20:30- 乘车返回奥蓝酒店 (二)主题二讨论日程安排 小组主题:财产与合同 分组地点:奥蓝酒店会议室 2 主持人: 李增刚 ( 14:00 - 15:30 ) 报告人及题目 李胜兰、麦景琦:专利立法保护与司法保护对我国技术进步影响的实证研究 许邦国、朱慧:专利制度与经济增长关系的实证研究 万 江:土地制度困境与工业用地价格管制失败 柯 西、柯华庆:农村集体土地产权界定的法律经济分析 茶歇( 15 : 30 - 15 : 40 ) 主持人: 朱 慧 ( 15:40 - 17:10 ) 李增刚:计算机病毒的制作与传播行为 张广辉:政府、开发商、农民与耕地违法 张锦洪:交易、合同和合同法的演进逻辑 肖永泼:劳动合同法与农民工劳动合同签订意愿 17:15- 18:30 乘车前往沙坪坝区瓷器口古镇钟府私家菜 ( 中途参观西南政法大学校园 ) 18:30- 19:30 晚宴 19:30- 20:30 参观瓷器口古镇 20:30- 乘车返回奥蓝酒店 (三)主题三讨论日程安排 小组主题:政府与规制 分组地点:奥蓝酒店会议室 3 主持人: 陈刚 ( 14:00 - 15:30 ) 报告人及题目 王凤荣、高飞:政府干预、企业生命周期与并购绩效 董雪兵,尹敬敬,文雁兵:资源约束与环境污染控制下的最优经济增长路径研究 王 箐:财政分权,政府竞争与非经济性公共物品提供 史振华:我国对外贸易行政垄断制度变迁研究 茶歇( 15 : 30 - 15 : 40 ) 主持人: 龙小宁 ( 15:40 - 17:10 ) 陈刚、李树:管制、腐败与幸福:来自 CGSS2006 的经验证据 董淳锷:公司法实施的激励机制研究 吴晓露、史晋川:双重俘获下的乳品质量安全监管 魏泽瑞:城乡建设用地增减挂钩及其衍生问题的法经济学分析 17:15- 18:30 乘车前往沙坪坝区瓷器口古镇钟府私家菜 ( 中途参观西南政法大学校园 ) 18:30- 19:30 晚宴 19:30- 20:30 参观瓷器口古镇 20:30- 乘车返回奥蓝酒店 6 月 24 日上午 论坛分组报告 (注:报告人发言时间为 10-15 分钟,讨论时间为 5 - 10 分钟) (一) 主题三讨论日程安排 小组主题:政府与规制 分组地点: 奥蓝酒店会议室 1 主持人: 董淳锷( 9:00 - 10:30 ) 报告人及题目 马汴京、谢作诗: FDI 流入改进中国政府质量了吗? 纪玉山、关键、王塑峰:经济稳定增长与碳排放双重目标优化模型 黄立君、陈焕远:博弈视角下的煤与气矿业权重置、利益冲突与解决办法 卢燕平、史振华:城乡联系、社会资本与区域经济增长实证研究 茶歇( 10 : 30 - 10 : 50 ) 闭幕式:详见闭幕式议程( 10:50 - 12:00 ) (二) 主题四讨论日程安排 小组主题:侵权与犯罪 分组地点: 奥蓝酒店会议室 2 主持人: 吴晓露 ( 9:00 - 10:30 ) 报告人及题目 陈春良:收入差距扩大只是增加侵财犯罪吗? 钱永坤、郝 贵:国有重点煤矿百万吨死亡率拐点之迷 赵海怡:责任规则威慑与激励效应的异化及矫正 李井奎、史晋川、张利风:不确定性、破产与侵权事故的预防 茶歇( 10 : 30 - 10 : 50 ) 闭幕式:详见闭幕式议程( 10:50 - 12:00 ) (三)主题五讨论日程安排 小组主题:公司与金融 分组地点:奥蓝酒店会议室 3 主持人: 李胜兰 ( 9:00 - 10:30 ) 报告人及题目 栾天虹:资本监管、公司治理与商业银行风险承担 宁文昕:保荐代表人、证券监管与保荐质量的提高 杨志明:《反垄断法》、市场结构与上市公司的经济绩效 周黎明:中外典当业研究述评 茶歇( 10 : 30 - 10 : 50 ) 闭幕式:详见闭幕式议程( 10:50 - 12:00 ) 6 月 24 日上午 闭幕式 ( 地点:奥蓝酒店学术报告厅 ) 10:50-12:00 闭幕式 主持人 黄少安 山东大学经济研究院 院长 主题演讲( 20 分钟): 龙小宁(厦门大学 王亚南经济研究院):权利假说理论与中国法治发展 各主题报告(各代表发言时间 8 分钟) 主题一代表发言 主题二代表发言 主题三代表发言 主题四代表发言 主题五代表发言 会议总结 史晋川 浙江大学社会科学学部主任、经济学院院长 12:00 午餐(凭代表证和餐券就餐) 地点: 奥蓝酒店 14:00 代表返程或自由活动 参会注意事项: 1、 会议期间请将手机设置为振动状态; 2、 遵守发言和讨论的时间安排,并请主持人适当控制发言议程; 3、 使用投影仪的主讲人请提前与会务组联系,将电子稿拷贝给会务组提前准备。
3110 次阅读|1 个评论
小学五年级的拓展功课——大教授们试试
热度 16 cissyludai 2012-6-3 17:29
儿子周末的拓展功课。 九宫格 横线1-9不重复、纵线1-9不重复、双线框内1-9不重复。     3     2   8   4               1   1 6     9       6 4   7     5                           7     8   4 3       1     4 5   3               2   7   6     1     答案: 7 9 3 4 1 2 6 8 5 4 8 5 3 7 6 2 9 1 2 1 6 8 5 9 3 7 4 6 4 9 7 3 1 5 2 8 5 3 8 2 9 4 7 1 6 1 2 7 5 6 8 9 4 3 9 6 2 1 8 3 4 5 7 3 5 1 9 4 7 8 6 2 8 7 4 6 2 5 1 3 9
415 次阅读|44 个评论
[转载]float和double的范围和精度
hudc04 2012-5-13 14:20
float与 double的范围和精度 1 范围 float 和 double 的范围是由指数的位数来决定的。 float 的指数位有 8 位,而 double 的指数位有 11 位,分布如下: float : 1bit (符号位) 8bits (指数位) 23bits (尾数位) double : 1bit (符号位) 11bits (指数位) 52bits (尾数位) 在数学中,特别是在计算机相关的数字(浮点数)问题的表述中,有一个基本表达法 :     value of floating-point = significand x base ^ exponent , with sign --- F.1   译为中文表达即为:     (浮点)数值 = 尾数 × 底数 ^ 指数,(附加正负号)---------------- F.2 于是, float 的指数范围为 -127~128 ,而 double 的指数范围为 -1023~1024 ,并且指数位是按补码的形式来划分的。其中负指数决定了浮点数所能表达的绝对值最小的数;而正指数决定了浮点数所能表达的绝对值最大的数,也即决定了浮点数的取值范围。 float 的范围为 -2^128 ~ +2^128 ,也即 -3.40E+38 ~ +3.40E+38 ; double 的范围为 -2^1024 ~ +2^1024 ,也即 -1.79E+308 ~ +1.79E+308 。 2 精度 float 和 double 的精度是由尾数的位数来决定的。浮点数在内存中是按科学计数法来存储的,其整数部分始终是一个隐含着的“ 1 ”,由于它是不变的,故不能对精度造成影响。 float : 2^23 = 8388608 ,一共七位,这意味着最多能有 7 位有效数字,但绝对能保证的为 6 位,也即 float 的精度为 6~7 位有效数字; double : 2^52 = 4503599627370496 ,一共 16 位,同理, double 的精度为 15~16 位。 单精度类型(float)和双精度类型(double)存储 2009-11-24 13:57 C 语言和C#语言中,对于浮点类型的数据采用单精度类型(float)和双精度类型(double)来存储,float数据占用32bit, double数据占用64bit,我们在声明一个变量float f= 2.25f的时候,是如何分配内存的呢?如果胡乱分配,那世界岂不是乱套了么,其实不论是float还是double在存储方式上都是遵从IEEE的规范 的,float遵从的是IEEE R32.24 ,而double 遵从的是R64.53。 无论是单精度还是双精度在存储中都分为三个部分: 符号位(Sign) : 0代表正,1代表为负 指数位(Exponent):用于存储科学计数法中的指数数据,并且采用移位存储 尾数部分(Mantissa):尾数部分 其中float的存储方式如下图所示: 而双精度的存储方式为: R32.24和R64.53的存储方式都是用科学计数法来存储数据的,比如8.25用十进制的科学计数法表示就为:8.25* ,而120.5可以表示为:1.205* , 这些小学的知识就不用多说了吧。而我们傻蛋计算机根本不认识十进制的数据,他只认识0,1,所以在计算机存储中,首先要将上面的数更改为二进制的科学计数 法表示,8.25用二进制表示可表示为1000.01,我靠,不会连这都不会转换吧?那我估计要没辙了。120.5用二进制表示为:1110110.1用 二进制的科学计数法表示1000.01可以表示为1.0001* ,1110110.1可以表示为1.1101101* ,任何一个数都的科学计数法表示都为1.xxx* , 尾数部分就可以表示为xxxx,第一位都是1嘛,干嘛还要表示呀?可以将小数点前面的1省略,所以23bit的尾数部分,可以表示的精度却变成了 24bit,道理就是在这里,那24bit能精确到小数点后几位呢,我们知道9的二进制表示为1001,所以4bit能精确十进制中的1位小数点, 24bit就能使float能精确到小数点后6位,而对于指数部分,因为指数可正可负,8位的指数位能表示的指数范围就应该为:-127-128了,所以 指数部分的存储采用移位存储,存储的数据为元数据+127,下面就看看8.25和120.5在内存中真正的存储方式。 首先看下8.25,用二进制的科学计数法表示为:1.0001* 按照上面的存储方式,符号位为:0,表示为正,指数位为:3+127=130 ,位数部分为,故8.25的存储方式如下图所示: 而单精度浮点数120.5的存储方式如下图所示: 那 么如果给出内存中一段数据,并且告诉你是单精度存储的话,你如何知道该数据的十进制数值呢?其实就是对上面的反推过程,比如给出如下内存 数据:0100001011101101000000000000,首先我们现将该数据分段,0 10000 0101 110 1101 0000 0000 0000 0000,在内存中的存储就为下图所示: 根据我们的计算方式,可以计算出,这样一组数据表示为:1.1101101* =120.5 而双精度浮点数的存储和单精度的存储大同小异,不同的是指数部分和尾数部分的位数。所以这里不再详细的介绍双精度的存储方式了,只将120.5的最后存储方式图给出,大家可以仔细想想为何是这样子的 下面我就这个基础知识点来解决一个我们的一个疑惑,请看下面一段程序,注意观察输出结果 float f = 2.2f; double d = (double)f; Console.WriteLine(d.ToString("0.0000000000000")); f = 2.25f; d = (double)f; Console.WriteLine(d.ToString("0.0000000000000")); 可 能输出的结果让大家疑惑不解,单精度的2.2转换为双精度后,精确到小数点后13位后变为了2.2000000476837,而单精度的 2.25转换为双精度后,变为了2.2500000000000,为何2.2在转换后的数值更改了而2.25却没有更改呢?很奇怪吧?其实通过上面关于两 种存储结果的介绍,我们已经大概能找到答案。首先我们看看2.25的单精度存储方式,很简单 0 1000 0001 001 0000 0000 0000 0000 0000,而2.25的双精度表示为:0 100 0000 0001 0010 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000,这样2.25在进行强制转换的时候,数值是不会变的,而我们再看看2.2呢,2.2用科学计数法表示应该为:将十进制的小数转换为二进制的小数 的方法为将小数*2,取整数部分,所以0.282=0.4,所以二进制小数第一位为0.4的整数部分0,0.4×2=0.8,第二位为0,0.8*2= 1.6,第三位为1,0.6×2 = 1.2,第四位为1,0.2*2=0.4,第五位为0,这样永远也不可能乘到=1.0,得到的二进制是一个无限循环的排列 00110011001100110011... ,对于单精度数据来说,尾数只能表示24bit的精度,所以2.2的float存储为: 但 是这样存储方式,换算成十进制的值,却不会是2.2的,应为十进制在转换为二进制的时候可能会不准确,如2.2,而double类型的数 据也存在同样的问题,所以在浮点数表示中会产生些许的误差,在单精度转换为双精度的时候,也会存在误差的问题,对于能够用二进制表示的十进制数据,如 2.25,这个误差就会不存在,所以会出现上面比较奇怪的输出结果。
11125 次阅读|0 个评论
[转载]C++ PRINTF 要用%f 不要用%lf
hitzhj1231 2012-4-24 17:09
问:有人告诉我不能在printf中使用%lf。为什么printf()用%f输出double型,而scanf却用%lf呢? 答:printf的%f说明符的确既可以输出float型又可以输出double型。 根据"默认参数提升"规则(在printf这样的函数的可变参数列表中 ,不论作用域内有没有原型,都适用这一规则)float型会被提升为double型。因此printf()只会看到双精度数。参见问题15.2。 对于scanf,情况就完全不同了,它接受指针,这里没有类似的类型提升。(通过指针)向float存储和向double存储大不一样,因此,scanf区别%f和%lf。 下表列出了printf和scanf对于各种格式说明符可以接受的参数类型。 格式 printf scanf %c int char * %d, %i int int * %o, %u, %x unsigned int unsigned int * (续) 格式 printf scanf %ld, %li long int long int * %lo, %lu, %lx unsinged long int unsigned long int * %hd, %hi int short int * %ho, %hu, %hx unsigned int unsigned short int * %e, %f, %g double float * %le, %lf, %lg n/a double * %s char * char * % n/a char * %p void void ** %n int * int * %% none none (严格地讲,%lf在printf下是未定义的,但是很多系统可能会接受它。要确保可移植性,就要坚持使用%f。) 参见问题12.15和15.2。 参考资料:
个人分类: 编程东东|3 次阅读|0 个评论
[转载]Matlab调用C语言程序简单实例
热度 1 linpandr 2012-4-10 15:31
Matlab调用C语言程序简单实例 matlab的功能强大,不仅仅因为matlab的强大的函数库和验算本式的计算方式,更重要的是因为他有强大的接口。 今天,我才抄着写出了一个自己的运行在matlab中的C程序,是书上原来的例子。但是,知道可以调用的惊奇还是十分令人愉快的。 我在matlab的自带编辑器中输入如下代码,并保存为fact.c,存在系统工作目录中。 #include "mex.h" void mexFunction ( int nlhs,mxArray *plhs ) { double n,j,*p; int i; n=mxGetScalar(prhs ); plhs =mxCreateDoubleMatrix(1,1,mxREAL); p=mxGetPr(plhs ); j=1.0; for(i=n;i1;i--) j=j*i; *p=j; } 这仅仅是一个求阶乘的简单的例子。 然后,我在matlab中输入mex fact.c 如果没有错误,一切都将十分正常,然后,我输入 y=fact(5) 将输出y= 120 这个例子十分简单,但是,事实说明了matlab的接口调用也不是高不可测的,只要有心,很快就可以上手的。
个人分类: MATLAB|11742 次阅读|1 个评论
[转载]Matlab调用C语言函数
linpandr 2012-4-10 14:23
Matlab调用C语言函数 如果我有一个用C语言写的函数,实现了一个功能,如一个简单的函数: double add(double x, double y) {  return x + y; } 现在我想要在Matlab中使用它,比如输入: a = add(1.1, 2.2) 3.3000 要得出以上的结果,那应该怎样做呢? 解决方法之一是要通过使用MEX文件,MEX文件使得调用C函数和调用Matlab的内置函数一样方便。MEX文件是由原C代码加上MEX文件专用的接口函数后编译而成的。 可以这样理解,MEX文件实现了一种接口,它把在Matlab中调用函数时输入的自变量通过特定的接口调入了C函数,得出的结果再通过该接口调回Matlab。该特定接口的操作,包含在mexFunction这个函数中,由使用者具体设定。 所以现在我们要写一个包含add和mexFunction的C文件,Matlab调用函数,把函数中的自变量(如上例中的1.1和2.2)传给mexFunction的一个参数,mexFunction把该值传给add,把得出的结果传回给mexFunction的另一个参数,Matlab通过该参数来给出在Matlab语句中调用函数时的输出值(如上例中的a)。 比如该C文件已写好,名为add.c。那么在Matlab中,输入: mex add.c 就能把add.c编译为MEX文件(编译器的设置使用指令mex -setup),在Windows中,MEX文件类型为mexw32,即现在我们得出add.mexw32文件。现在,我们就可以像调用M函数那样调用MEX文件,如上面说到的例子。所以,通过MEX文件,使用C函数就和使用M函数是一样的了。 我们现在来说mexFunction怎样写。 mexFunction的定义为: void mexFunction(      int nlhs,      mxArray *plhs ) { } 可以看到,mexFunction是没返回值的,它不是通过返回值把结果传回Matlab的,而是通过对参数plhs的赋值。mexFunction的四个参数皆是说明Matlab调用MEX文件时的具体信息,如这样调用函数时: b = 1.1; c = 2.2; a = add(b, c) mexFunction四个参数的意思为: nlhs = 1,说明调用语句左手面(lhs-left hand side)有一个变量,即a。 nrhs = 2,说明调用语句右手面(rhs-right hand side)有两个自变量,即b和c。 plhs是一个数组,其内容为指针,该指针指向数据类型mxArray。因为现在左手面只有一个变量,即该数组只有一个指针,plhs 指向的结果会赋值给a。 prhs和plhs类似,因为右手面有两个自变量,即该数组有两个指针,prhs 指向了b,prhs 指向了c。要注意prhs是const的指针数组,即不能改变其指向内容。 因为Matlab最基本的单元为array,无论是什么类型也好,如有double array、 cell array、 struct array……所以a,b,c都是array,b = 1.1便是一个1x1的double array。而在C语言中,Matlab的array使用mxArray类型来表示。所以就不难明白为什么plhs和prhs都是指向mxArray类型的指针数组。 完整的add.c如下: // add.c #include "mex.h" // 使用MEX文件必须包含的头文件 // 执行具体工作的C函数 double add(double x, double y) {  return x + y; } // MEX文件接口函数 void mexFunction(  int nlhs,  mxArray *plhs ) {  double *a;  double b, c;  plhs = mxCreateDoubleMatrix(1, 1, mxREAL);  a = mxGetPr(plhs );  b = *(mxGetPr(prhs ));  c = *(mxGetPr(prhs ));  *a = add(b, c); } mexFunction的内容是什么意思呢?我们知道,如果这样调用函数时: output = add(1.1, 2.2); 在未涉及具体的计算时,output的值是未知的,是未赋值的。所以在具体的程序中,我们建立一个1x1的实double矩阵(使用mxCreateDoubleMatrix函数,其返回指向刚建立的mxArray的指针),然后令plhs 指向它。接着令指针a指向plhs 所指向的mxArray的第一个元素(使用mxGetPr函数,返回指向mxArray的首元素的指针)。同样地,我们把prhs 和prhs 所指向的元素(即1.1和2.2)取出来赋给b和c。于是我们可以把b和c作自变量传给函数add,得出给果赋给指针a所指向的mxArray中的元素。因为a是指向plhs 所指向的mxArray的元素,所以最后作输出时,plhs 所指向的mxArray赋值给output,则output便是已计算好的结果了。 上面说的一大堆指向这指向那,什么mxArray,初学者肯定都会被弄到头晕眼花了。很抱歉,要搞清楚这些乱糟糟的关系,只有多看多练。 实际上mexFunction是没有这么简单的,我们要对用户的输入自变量的个数和类型进行测试,以确保 输入正确。如在add函数的例子中,用户输入char array便是一种错误了。 从上面的讲述中我们总结出,MEX文件实现了一种接口,把C语言中的计算结果适当地返回给Matlab罢了。当我们已经有用C编写的大型程序时,大可不必在Matlab里重写,只写个接口,做成MEX文件就成了。另外,在Matlab程序中的部份计算瓶颈(如循环),可通过MEX文件用C语言实现,以提高计算速度。
个人分类: MATLAB|2658 次阅读|0 个评论
DNA 双螺旋草图
热度 1 xupeiyang 2012-4-7 07:57
http://images.wellcome.ac.uk/indexplus/image/B0004367.html 这幅双螺旋—扭曲阶梯的图片描述了地球上生命体各种类型的代码—追溯到 1953 年,以及描述了英国科学家弗朗西斯·克里克及其美国合作者詹姆斯·沃森创建的自制金属模型。 为了解决当时研究证据提出的难题,他们通过物理模型结构复杂的分子,获取了新的发现。 这幅 DNA 铅笔草图为克里克所作,构成维康图书馆大量克里克作品的一部分。 这幅图说明了双螺旋的几个机构特征:首先为右旋,双链以相反的方向运转;核苷酸,即链的构成块,具有形成骨骼的一个部分和伸向螺旋中间的一个部分(碱基);一个链中的内部伸向碱基相互对齐,因此能够与相反链中的碱基配对。 最后一个特征对 DNA 十分关键,这个特征能够执行将基因信息从一代传给下一代的功能。 克里克是在他和沃森创建出著名的模型之前还是之后绘制了这幅草图,至今无法得知,但这幅草图诠释了简单的图解能够帮助人们理解复杂问题的作用。 创作者 克里克, 弗朗西斯 (1916-2004) 创建日期 公元 1953年 标题原文 Sketch of the DNA Double Helix by Francis Crick 《自然》杂志上的经典短文是美国生物学家詹姆斯·杜威·沃森(James Dewey Watson)与英国生物学家弗朗西斯·克里克(Francis Crick)的神来之笔。1953年4月25日,沃森和克里克在这篇题为“核酸的分子结构”的论文中向世人宣告:引导生物发育和生命机能运作的脱氧核糖核酸(DNA)具有双螺旋结构。他们用了大约1100个单词和1张图阐述他们的重大发现,整篇文章的长度仅仅一页出头。1962年,沃森和克里克与英国分子生物学家莫里斯·威尔金斯(Maurice Wilkins)分享了诺贝尔生理学或医学奖。
个人分类: 科学名人|4462 次阅读|4 个评论
[转载]调用波形文件的程序
linpandr 2012-3-8 20:37
下面是调用波形文件的程序,但是画出来之后只有0点以的部分,而同样的文件直接导入MATLAB工具箱读取就是完整的,请问这是为什么呢?谢谢! % 装载信号 fidin=fopen('F:\随书光盘\2006060703断裂_1_10_85768.csv'); % 打开波形文件 fidout=fopen('mkmatlab.txt','w'); % 创建MKMATLAB.txt文件 while ~feof(fidin) % 判断是否为文件末尾 tline=fgetl(fidin); % 从文件读行 if double(tline(1))=48double(tline(1))=57 % 判断首字符是否是数值 fprintf(fidout,'%s\n\n',tline); % 如果是数字行,把此行数据写入文件MKMATLAB.txt continue % 如果是非数字继续下一次循环 end end fclose(fidout); MK=importdata('MKMATLAB.txt'); % 将生成的MKMATLAB.txt文件导入工作空间, matlab1=textread('MKMATLAB.txt'); matlab1=matlab1'; x = matlab1; plot(x); 图见附件 把以下语句: if double(tline(1))=48double(tline(1))=57 改为 if double(tline(1))=45|48double(tline(1))=57 因为48相当于ASCII码的0,这样把‘-’号都排除了,即 ‘-’号开始的行都没有被读入。修改后的图如下。 下面是调用波形文件的程序,但是画出来之后只有0点以的部分,而同样的文件直接导入MATLAB工具箱读取就是完整的,请问这是为什么呢?谢谢! % 装载信号 fidin=fopen('F:\随书光盘\2006060703断裂_1_10_85768.csv'); % 打开111.txt文件 fidout=fopen('mkmatlab.txt','w'); % 创建MKMATLAB.txt文件 while ~feof(fidin) % 判断是否为文件末尾 tline=fgetl(fidin); % 从文件读行 if double(tline(1))=48double(tline(1))=57 % 判断首字符是否是数值 fprintf(fidout,'%s\n\n',tline); % 如果是数字行,把此行数据写入文件MKMATLAB.txt continue % 如果是非数字继续下一次循环 end end fclose(fidout); MK=importdata('MKMATLAB.txt'); % 将生成的MKMATLAB.txt文件导入工作空间, matlab1=textread('MKMATLAB.txt'); matlab1=matlab1'; x = matlab1; plot(x); 附件: 图 ( 10.35 K ) 附件: 2006060703断裂_1_10_85768 ( 3.7 K )
2351 次阅读|0 个评论
[转载]MEX文件中给一个double矩阵赋值的几种方法
joel1019 2012-2-8 04:09
MEX文件中给一个double矩阵赋值的几种方法 MEX文件中想给一个mxArray赋值,有如下几种方法: 1、直接指向mxArray元素进行赋值,如: plhs = mxCreateDoubleMatrix(1, 2, mxREAL); // 一行二列 double *p = mxGetPr(plhs ); // 指向mxArray第一个元素 *p = 123; ++p;// 指向mxArray下一个元素 *p = 321; 2、使用C函数memcpy,如: #include "mex.h" #include "string.h" // memcpy函数必须此头文件 void mexFunction(/*...*/) {  plhs = mxCreateDoubleMatrix(1, 2, mxREAL);  double *p = mxGetPr(plhs );  double data = mxCreateDoubleMatrix(1, 2, mxREAL); double *data = (double *)mxCalloc(2, sizeof(double)); data = 123; data = 321; mxFree(mxGetPr(plhs )); mxSetPr(plhs , data); 要注意的是,mxSetPr函数不会释放原本已存在的内存,所以在使用mxSetPr函数前,先使用mxFree把mxArray中内容的内存释放,否则后果严重。另外,mxSetPr函数的第二个参数必须是使用mxCalloc分配内存,注意mxCalloc函数前加上(double *),把mxCalloc返回的(void *)类型强制转换为(double *)。 详细内容参加Matlab帮助里的External Interfaces一章。
个人分类: Matlab|5091 次阅读|0 个评论
[转载]CCSD = Coupled-cluster single-and double
chnfirst 2012-1-6 17:16
CCSD = Coupled-cluster single-and double http://emuch.net/html/200911/1690349.html CCSD(T)来说,其实CCSD就是单双重耦合簇方法(其中的T代表了三重态以微绕的形式考虑到其中)。 http://book.kongfz.com/19206/133952143/ 量子化学中的计算方法【库位:2号】 书籍作者:陈飞武 图书出版社:科学出版社 图书品相:九五品 库 存 量:5 本 图书售价: 16.00 元 图书原价:40.00元 出版时间: 2008 开本:不详 页数:208 页 装订:平装 ISBN:9787030219794 图书详细描述: 版次:第1版 基本信息 书名:量子化学中的计算方法 原价:40.00元 作者:陈飞武 出版社:科学出版社 出版日期:2008年6月1日 ISBN:9787030219794 字数: 页码:208 版次:第1版 装帧:平装 开本: 商品重量:322 g 编辑推荐 《量子化学中的计算方法》由科学出版社出版。 内容提要 《量子化学中的计算方法》主要介绍量子化学的基本原理和相应的计算方法。全书共8章。具体内容包括数学预备知识,量子力学导论,Hartree-Fock方程及自洽场计算,单电子和双电子积分计算,组态相互作用计算,微扰理论,耦合簇理论和约化密度矩阵理论。《量子化学中的计算方法》可作为高等院校化学系物理化学专业、量子化学专业或其他相关专业研究生和大学高年级学生的教科书,也可供相关领域的科研人员阅读参考。 目录 前言第1章 数学预备知识1.1 矢量1.2 矩阵1.3 各种常用矩阵1.4 行列式的计算1.5 矢量的正交化1.6 线性变换1.7 变分法参考文献第2章 量子力学导论2.1 原子和分子体系的schrodinger方程2.2 波函数2.3 哈密顿矩阵元的计算2.4 角动量和自旋参考文献第3章 Hartree-Fock方程及自洽场计算3.1 Hartree-Fock方程3.2 Hartree-Fock方程的性质3.3 闭壳层体系3.4 开壳层体系3.5 自洽场迭代计算3.6 大小一致性和氢分子的离解参考文献第4章 单电子和双电子积分计算4.1 GaUSS基函数的单电子积分4.2 Gauss基函数的双电子积分参考文献第5章 组态相互作用计算5.1 二次量子化5.2 组态波函数5.3 Davidson对角化方法5.4 组态相互作用的大小一致性5.5 多组态自洽场方法参考文献第6章 微扰理论6.1 单参考态微扰理论6.2 多参考态微扰理论6.3 单参考态微扰理论的应用6.4 多参考态微扰理论的应用参考文献第7章 耦合簇理论7.1 独立电子对近似7.2  双重耦合簇理论 7.3 一般耦合簇理论参考文献第8章 约化密度矩阵理论8.1 约化密度矩阵简介8.2 约化密度矩阵8.3 约化密度矩阵的二次量子化8.4 简缩Schrodinger方程参考文献
个人分类: 理论|0 个评论
Espresso
热度 1 amelielele 2011-12-8 23:44
很久以前知道咖啡里面有一种叫做espresso,似乎需要蒸馏,压制出来的,似是咖啡中非常经典的一种。今天下午16:00有课,忽然涌起一股冲动去 Portland Building 里的COSTA买杯咖啡来提提神。上次Lu推荐喝的一种味道非常不错,叫做Cacha(希望名字我没有记错),但今天店员告诉我没有巧克力了,所以无法调 制由咖啡和巧克力混合而成的Cacha,索性就来一杯espresso吧,“for single or double, stay or for take-away?” 一分钟前在menu上看见espresso是Classic里排在第一位的,应该不会让我失望。 排在我前面的两 位顾客都拿到很大的纸杯,我满怀期待我的espresso。只见店员盖上一仅有2.5厘米半径,高约5厘米的袖珍纸杯,颇为熟练的轻 唤:“espresso!”我大跌眼镜了,是在糊弄我吗?打开杯盖,发现里面的液体不足1/5,我惊讶的望着店员:“espresso? espresso with single?”难道是平常人们都喝double的吗?店员肯定的望着我“yes, this is espresso! ,for single!”不想再进一步出洋相,我准备离开,至少我知道下一回我再也不会点espresso了。我品尝了一小口,味道相当的浓烈,难以下咽,但是不 能浪费,1.35镑呢!在Blackwell书店里逛了一会,我发现我并没有刚来时的好心情了,相反想拿一些甜的东西来补偿一下,学生活动中心 (student union's shop)买了一小袋酸奶葡萄干,还是挺郁闷的! 准备回来office时刚好下着雨,英国的天气总是 这样一会晴一会雨。虽然回到office不需要一分钟,这一分钟,雨却是越来越大了,奔跑中我想着回来的第一件事是查字典,确定COSTA的店员没有愚弄 我。到了office门口,我已经成了落汤鸡了。犹豫了一下这副样子被同学看见会不会被笑话了,管他呢!可一开门我就后悔了,本想不知不觉进 来,Marta见我的样子已忍不住哈哈笑了起来,大家都望着我。 “So heavy!” “The moment I decided to come back, it began to rain, and got heavier and heavier.”大家轻松的笑起来。 “Marta, may I ask you what's espress?”来自意大利的Marta,我猜测她应该对咖啡深有研究。 “It's very strong and condensed. In Italy, we only drink espresso, but the espresso in the UK is something like rubbish. Uh, I mean , in fact, it's quite different here.” 我略微relieved。 “Is it so small like this?”我向她展示我那个袖珍纸杯。 “Yes, though the flavor is differnt, the amount is the same, they are very strong. You didn't add sugar in it? You are supposed to add sugar in it!” 得,还是没有掌握方法。 Marta再次下我强调了在英国espresso是多么多么的不正宗。 “I hope I may go to Italy, and try some decent ones! It's so bitter that it tastes like Chinese medicine!” 好啦,得到的教训,下回品尝咖啡,还是不要擅自行动的好!呵呵
个人分类: 心情笔记|3289 次阅读|3 个评论
[转载]DNA双螺旋结构先驱者之间的矛盾被进一步揭示
duke01361 2010-10-1 21:30
29 September 2010 Last updated at 18:43 'Lost' letters show strain between DNA pioneers By Katia Moskvitch Science reporter, BBC News James Watson (left) was only 24 when together with Francis Crick (right) he published the paper that first described the structure of DNA Newly-found letters of the scientists who discovered the structure of DNA highlight tensions around this major scientific breakthrough. Extracts from the missing correspondence are published in the journal Nature. The smoke of witchcraft will soon be getting out of our eyes Maurice Wilkins Biologist Maurice Wilkins, James Watson and Francis Crick won the 1962 Nobel Prize in Medicine for the DNA-related work. But many others contributed, including Rosalind Franklin - whose efforts were called witchcraft in one letter. All three Nobel Prizewinners worked in molecular biology, but in different labs. Essentially, there were two main groups, pursuing the discovery of the DNA (deoxyribonucleic acid) structure: Dr Wilkins and Dr Franklin at King's College in London, and Dr Watson and Dr Crick at the Cavendish Laboratory at Cambridge University. Besides strained relationships, the letters and postcards also give insights into the personalities of the key players. Rosalind Franklin's work was crucial in the discovery of the structure of DNA The Cambridge team used some of Dr Franklin's results to build their first DNA model in December 1951. This triple-helix model was wrong, and the scientists were barred from doing any further DNA work. Dr Wilkins then wrote to his colleagues: This is to say how bloody browned off I am entirely, and how rotten I feel about it all, and how entirely friendly I am (though it may appear differently). We are really between forces which may grind all of us into little pieces But Dr Crick and Dr Watson appeared to be rather breezy: cheer up, and take it from us that even if we kicked you in the pants, it was between friends, the pair wrote in response. We hope our little burglary will at least produce a united front in your group! The last phrase referred to strained relations between Dr Wilkins and Dr Franklin. When the latter arrived to King's College, her colleague thought that she would be working for him, but she believed otherwise. This misunderstanding poisoned their relationship, and the tensions were highlighted even further in other letters. Just before Dr Franklin was to leave King's College, Dr Wilkins wrote to the Cambridge scientists that the smoke of witchcraft will soon be getting out of our eyes. Sexism Explaining the situation to BBC News, Nature's commissioning editor Sara Abdullah said it added to the canon of awful things said about . I think 'sexist' is what we are groping around for. Maurice Wilkins shared the Nobel Prize with Dr Watson and Dr Crick Obviously, this is a different time, it's 1953. There was personal tension; she was very unusual in being a leading woman in science at that time. And there were these different styles of working - all these things are captured there, in those few words. In early 1953, Maurice Wilkins showed James Watson the famous Photograph 51. It was the crucial X-ray image of DNA made by Dr Franklin in the previous months, and it helped the two Cambridge biologists to develop the historic - and correct - double-helix model. To think that Rosie had all the 3D data for nine months and wouldn't fit a helix to it, and there was I taking her word for it that the data was anti-helical, wrote Dr Wilkins to Dr Crick. Christ. And when the study was published in Nature in April 1953, there were only vague references to Dr Franklin's contribution to the titanic achievement in molecular biology. The correspondence had been thought lost. The famous paper on the structure of DNA was published on 25 April, 1953 But it was found earlier this year by Alexander Gann and Jan Witkowski of Cold Spring Harbor Laboratory in New York among papers that had belonged to another scientist, Sydney Brenner, who had shared an office with Francis Crick in Cambridge. Related Internet links Nature: The lost correspondence of Francis Crick
个人分类: Science in action|5064 次阅读|0 个评论

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-6-15 10:56

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部