谈谈在MATLAB 编程过程中要注意的问题? 小弟在用matlab编程过程中,遇到以下问题

作者&投稿:辕杜 (若有异议请与网页底部的电邮联系)
1.屡次运行,天生相同的随机数方法:

  用rand('state',S)设定种子

  S为35阶向量,最简略的设为0就好

  例:

  rand('state',0);rand(10)

  2. 任何天生相同的随机数方法:

  试着产生和时间相关的随机数,种子与当前时间有关.

  rand('state',sum(100*clock))

  即:

  rand('state',sum(100*clock)) ;rand(10)

  只要执行rand('state',sum(100*clock)) ;的当前计算机时间不现,天生的随机值就不现.

  也就是要是时间相同,天生的随机数照旧会相同.

  在你计算机速度足够快的情况下,试运行一下:

  rand('state',sum(100*clock));B=rand(5,5);rand('sta te',sum(100*clock));B=rand(5,5);

  B和B是相同.

  所以提议再增长一个随机变量,酿成:

  rand('state',sum(100*clock)*rand⑴);

  %

  听说matlab 的rand 函数还存在其它的根天性的问题,彷佛是非随机性问题.

  没具体研究及讨论,验证过,不感多言.

  有兴趣的可以查阅:

  <<B strong nonrandom pattern in Matlab default random number generator>>

  Petr Savicky

  Institute of Domputer Science

  Bcademy of Sciences of DR

  Dzech Republic

  savicky@cs.cas.cz

  September 16, 2006

  Bbstract

  The default random number generator in Matlab versions between 5 and at least

  7.3 (R2006b) has a strong dependence between the numbers zi+1, zi+16, zi+28 in the

  generated sequence. In particular, there is no index i such that the inequalities

  zi+1 < 1/4, 1/4 zi+16 < 1/2, and 1/2 zi+28 are satisfied simultaneously. Thellos

  fact is proved as a consequence of the recurrence relation defining the generator. B

  random sequence satisfies the inequalities with probability 1/32. Bnother example

  demonstrating the dependence is a simple function f with values �6�11 and 1, such that

  the correlation between f(zi+1, zi+16) and sign(zi+28 �6�1 1/2) is at least 0.416, whellole it

  should be zero.

  B simple distribution on three variables that 关了ly approximates the joint

  distribution of zi+1, zi+16, zi+28 is described. The region of zero density in the

  approximating distribution has volume 4/21 in the three dimensional unit cube. For

  every integer 1 k 10, there is a parallelepiped with edges 1/2k+1, 1/2k and 1/2k+1,

  where the density of the distribution is 2k. Numerical simulation confirms that the

  distribution of the original generator matches the approximation withellon small random

  error corresponding to the sample size.

F12设置断点F10单步调试尽量利用matlab的向量运算,少用循环。每一行代码末尾加分号,不在命令行显示计算结果,可以加快代码运行速度。……

这是考试内容吗?

matlab编程中的一些问题~

1、bounds=[-1;1]'得到的其实就是一个行向量[-1 1],你可以把它复制来运行一下就行了;单引号就是转置的意思,因为“;”表示“-1”和“1”是处于两行的,转置一下就回来了。
2、(bounds(:,2)-bound(:,1))是说“bounds”这个二维数组的第二列元素减去第一列元素。
3、不是。你这样就行了:
function S=bgg(x,y,z,o,p)
。。。
S(i)= ;或者直接S= ;
就是说你把函数中的变量,不管是向量还是矩阵,直接放在返回值处就行。甚至
m=3;S=[1 5 9 4];你想二者都返回,那么function [m,S]=bgg(x,y,z,o,p),并且主函数这样[m,S]=bgg(x,y,z,o,p),接收就行了。
4、方括号主要是把向量或矩阵的值罗列出来等功能,小括号一是表示运算优先级,二是作为引用元素的角标,三是包含函数的输入参数。

数组的下标有问题
注意:不能是除正整数以外的任何数
换句话说只能是正整数!
你检查一下,是不是有小数或者0,负数一类的了?