⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mathfaq.txt

📁 matlab编程比较有用的电子书之一
💻 TXT
📖 第 1 页 / 共 5 页
字号:
6)Matlab中如何作线性拟合/线性回归/多元线性回归? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21, BigGreen/MathTools # 

  

  

        即用y=a*x+b来拟合一组数据{{x1,y1},{x2,y2}…{xn,yn}} 

        matlab中使用polyfit 

        x=data(:,1); 

        y=data(:,2); 

        p=polyfit(x,y,1); 

        p(1)为斜率a,p(2)为截距b 

  

        多元线性回归即用y=a1*x1+a2*x2+..+am*xm来拟合数据点{x1i,x2i,…xmi,yi} 

  

        (i=1~n) 

  

          |x11,x21,…xm1| 

        A=|x12,x22,…xm2| 

          |……………   | 

          |x1n,x2n,…xmn| 

  

        Y={y1,y2,y3,…,yn}' 

  

        则系数{a1,a2,…,am}'=pinv(A)*Y 

        在matlab中使用 

        coeff=A\Y 

        则可以得到最小二乘意义上的拟合系数 

  

  

=================================== 

7)Matlab中如何作圆回归? 

:#Peter Boettcher (boettcher@ll.mit.edu),2002/5/16, comp.soft-sys.matlab# 

  

        Q5.5: How can I fit a circle to a set of XY data? 

        ================================================= 

  

           An elegant chunk of code to perform least-squares circle fitting 

        was written by Bucher Izhak and has been floating around the 

        newgroup for some time.  The first reference to it that I can 

        find is in: 

  

                 function [xc,yc,R,a] = circfit(x,y) 

                 %CIRCFIT  Fits a circle in x,y plane 

                 % 

                 % [XC, YC, R, A] = CIRCFIT(X,Y) 

                 % Result is center point (yc,xc) and radius R.A is an 

                 % optional output describing the circle's equation: 

                 % 

                 %   x^2+y^2+a(1)*x+a(2)*y+a(3)=0 

  

                 % by Bucher izhak 25/oct/1991 

  

                 n=length(x);  xx=x.*x; yy=y.*y; xy=x.*y; 

                 A=[sum(x) sum(y) n;sum(xy) sum(yy)... 

                    sum(y);sum(xx) sum(xy) sum(x)]; 

                 B=[-sum(xx+yy) ; -sum(xx.*y+yy.*y) ; -sum(xx.*x+xy.*y)]; 

                 a=A\B; 

                 xc = -.5*a(1); 

                 yc = -.5*a(2); 

                 R  =  sqrt((a(1)^2+a(2)^2)/4-a(3)); 

  

           Tom Davis provided a more sophisticated approach that works 

        for more cases in  and Code included. 

  

  

=================================== 

8)Matlab中如何绘制箭头? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21, SMTH/MathTools # 

  

        到http://www.mathworks.com/matlabcentral/fileexchange/index.jsp 

        2-D Plotting and Graphics中查找arrow.m,或者 

        http://www.mathworks.com/matlabcentral/spotlight/arrows.shtml 

        http://www.math.umd.edu/~jec/matcomp/matcompmfiles/mfiles.html 

  

  

=================================== 

9)Matlab中如何作二维数据的插值? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21, BigGreen/MathTools # 

  

  

        对于一维、二维、三维规则数据点阵使用interp1/interp2/interp3, 

        二维、三维非规则数据用griddata/griddata3 

  

  

=================================== 

10)Matlab中如何绘制三维数据阵? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21, BigGreen/MathTools # 

  

  

        如果使用matlab,打开帮助窗口,在目录树上找到 

        MATLAB\Using Matlab\ 

           3-D Visualization: Volume Visualization Techniques 

  

        如果图形复杂,建议使用Tecplot,参见Tecplot手册中数据格式,将你 

        的三维数据读入Tecplot,双击zone,可以设置mesh/contour/surface 

        transparency等。 

  

        在Field菜单中有3D Iso-surface Details和3D Slice Details,可以绘制等值 

  

        面和任意平面的截面图。 

  

  

=================================== 

11)Matlab中如何注解一大段代码? 

:#hyphone,2002/7/6, SMTH/MathTools # 

  

        注释大段代码选中代码,Ctrl+R;取消注释,选中代码,Ctrl+T。 

        或者用Edit菜单或者右键弹出中的注释。 

  

:#misc,2002/6/21, SMTH/MathTools # 

  

        if(0) 

        大段的代码 

        end 

  

  

=================================== 

12)Matlab中如何计算程序运行的时间? 

:#misc,2002/6/21, SMTH/MathTools # 

  

        tic 

          your_code; 

        toc 

        或者使用 

        t=cputime; 

          your_operation; 

        cputime-t 

  

  

=================================== 

13)Matlab中如何改变默认的工作路径? 

:#SindyGong, 2002/4/7, SMTH/MathTools # 

  

        编辑一个startup.m文件,其中cd yourpath 

        或者在X:\matlab\toolbox\local\matlabrc.m的最后添加cd yourpath 

        参见: 

        http://www.mathworks.com/support/solutions/data/25164.shtml 

  

  

=================================== 

14)Matlab如何改变默认的图形字体? 

:#comp.soft-sys.matlab FAQ# 

  

        编辑一个startup.m文件,其中 

        set(0,'DefaultObjectnamePropertyName',Value) 

        或者在X:\matlab\toolbox\local\matlabrc.m的最后添加 

        set(0,'DefaultObjectnamePropertyName',Value) 

  

  

=================================== 

15)如何在Matlab中实现交互操作? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

  

  

        如果只在命令窗口进行交互操作,请参见demo中的例子,主要是 

        通过input命令和pause/clear/disp等实现的,还有一些窗口资源可以使 

        用: 

        uigetfile,uiputfile,uiwait,uisetcolor,uisetfont, uiopen,uisave 

        inputdlg,msgbox,helpdlg,questdlg,warndlg,errordlg 

  

  

=================================== 

16)Matlab中为什么只能在小数点后显示四位? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

  

  

        用format命令来改变命令窗口数字的显示格式和精度,但不会影 

        响matlab的计算精度,matlab的矩阵运算默认都是双精度浮点型运算。 

  

  

  

=================================== 

17)Matlab如何在命令窗口按照格式输出? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,SMTHTools # 

  

        fprintf(1,"your_format_string",var1,var2,…); 

  

  

=================================== 

18)如何在Matlab中画隐函数曲线? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

  

  

        在http://www.mathworks.com/matlabcentral/fileexchange/index.jsp 

        查找implicit,会找到一个Arthur Jutan写的implot.m 

        Mathematica中绘制隐函数用ImplicitPlot[] 

        或者ImplicitPlot3D[] 

        Maple中为implicitplot(),implicitplot3d() 

        参见 

        http://engineering.dartmouth.edu/~fangq/MATH/download/source/ 

         ImplicitPlot3D.htm 

  

  

=================================== 

19)Matlab中什么函数可以删除矩阵的某一行或列? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

  

  

        A(j,:)=[];  %删除A的第j行 

        A(:,i)=[];  %删除A的第i列 

  

  

=================================== 

20)Matlab中能开的最大数组是由什么决定的? 

:# chenft (mike),2002/6/1, SMTH/MathTools # 

  

      I have had similar problems. Below is an explanation I received from 

      Ian Boyd 

      from Mathworks (just giving credit where credit is due) that explains 

      what's happening. You solution is to run matlab with the -nojvm mode. 

      "The heap memory system in JAVA consists of data and handle elements. 

      When you allocate a variable you get a handle and data. As long as 

      data has an associated handle, the JVM considers it valid and 

      will not clean it up. 

  

      However, when you call the clear function in MATLAB, all handles are 

      destroyed, and the data associated is now invalid. This means that 

      the JAVA engine can free up that data (garbage collection), but does 

      not mean that it will clean it up at that moment. 

  

      Calling the PACK command encourages JAVA to run the garbage collector 

      and de-fragment the memory. But it does not force it to (This is part 

  

      of the JAVA design). Even though the memory is 'freed' on the heap, 

      it is not actually free to the OS, it is only free to the JVM. Here 

      is one way to think of it: 

  

      [MATLAB] 

      [JAVA] 

        [OS] 

      MATLAB runs on JAVA (virtual machine), and Java runs on the OS 

      (physical machine). So when MATLAB is running in JAVA mode memory 

      allocations  are requested from the JRE, not the OS. 

  

      One problem you may be running into is that the default maximum 

      JAVA heap size is relatively low ( <= 64 MB), so that is all the 

      memory one session of MATLAB will ever get on your system. 

  

      The good news is that you can increase this value. You will need 

      to create a java.opts file in $MATLAB/bin/$ARCH (or in the current 

      directory when  you start MATLAB) and put the following command: 

  

      %%%BEGIN CODE%%% 

      maxHeapSize = 268435456 

      %%%END CODE%%% 

  

      This will give you 256MB of JVM memory and you can adjust the 

      parameter as needed. 

  

      Note: $MATLAB is the root directory and $ARCH is your system 

      architecture. This solution works on Windows as well as Solaris, 

      Linux,Alpha, and SGI. A similar operation is possible on IBM and 

      HPUX, but with a different syntax. 

  

      For the 1.1.8 JVM (Windows, Linux, Solaris, Alpha, SGI) our 

      defaults are: 

  

         minHeapSize = 16000000 

         maxHeapSize = 64000000 

  

      These are the structure field names in  that correspond to 

      -ms and -mx, and the settings above are roughly 16MB and 64MB. 

      To investigate the Java heap a bit, ask via the following: 

         >> java.lang.Runtime.getRuntime.totalMemory 

         >> java.lang.Runtime.getRuntime.freeMemory 

  

      When the free memory hits zero, Java will double the heap size 

      (up to the maximum setting). 

  

      If you choose to run without Java, you will remove the overhead 

      of the middle man, but you will also lose some MATLAB functionality 

      (mostly graphics and the Editor). You will still have most 

      of the computational power though. 

  

      Without JAVA, memory management will come directly from the OS, 

      and a CLEAR operation will result in memory being freed back to 

      the OS. 

  

  

=================================== 

21)如何在Matlab中添加新的工具箱? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

  

  

        如果是Matlab安装光盘上的工具箱,重新执行安装程序,选中即可。 

        如果是单独下载的工具箱,一般情况下仅需要把新的工具箱解压到某 

        个目录,然后用addpath(对于多个目录的使用genpath())或者pathtool添 

        加工具箱的路径,然后用which newtoolbox_command.m来检验是否可 

        以访问。如果能够显示新设置的路径,则表明该工具箱可以使用了。 

        具体请看工具箱自己代的README文件。 

  

  

  

=================================== 

22)如何读写Matlab的.mat文件? 

:#FangQ(Qianqian.Fang@Dartmouth.Edu),2002/6/21,BigGreen/MathTools # 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -