使用MATLAB生成随机多项式 [英] Generate random polynomials with MATLAB

查看:311
本文介绍了使用MATLAB生成随机多项式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想生成参数为(n,m)的随机二进制多项式.

I want to generate random binary polynomials with parameters (n,m).

n是要生成的多项式的数量 m是每个多项式的元素数.

n is the number of polynomials to be generated and m is the number of elements of each polynomials.

同时,我需要多项式是唯一的. 而且我还需要排除所有元素等于零的结果.

At the same time I need it's polynomial to be unique. And I also need to exclude the result with all elements equal to zero.

例如对于n=3m=3,我正在寻找类似的东西 [1 0 1] [1 0 0] [1 1 1].

For example for n=3 and m=3 I am looking for something like [1 0 1] [1 0 0] [1 1 1].

mat实验室中是否可以使用任何命令来获得上述结果?我还想避免for循环!

Is there any command in mat lab which I can use to have the above results?? I would also like to avoid the for loop if possible!!

我发现命令unique(rand(n,m)>=0.5,'rows')将完成这项工作.但这不能保证结果[0 0 0]将被排除

I found that the command unique(rand(n,m)>=0.5,'rows') will do the job. But this does not guarantee that the result [0 0 0] will be excluded

有什么想法吗?

推荐答案

每个多项式都可以解释为1到2 ^ m-1之间的二进制数.

Each of your polynoms could be interpreted as a binary number between 1 and 2^m-1.

%get a random subset of size n
X=randperm(2^m-1,n);
%convert it to a matrix
X=dec2bin(X)-'0';

这篇关于使用MATLAB生成随机多项式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆