数统 应数 20121323003 王妍 数统 应数 20121323022 胡可旺
1 生成5阶矩阵,使其元素满足均值为1,方差为4的正态分布; 代码:y=1+sqrt(4)*randn(5) 结果:
2,生成一个20行5列矩阵A,其元素分别以概率0.7、0.1、0.2取自0、1、4这三个整数, 然后将“删除A的全零行”之后的结果赋给矩阵B; for i = 1:20 for j = 1:5
p = rand(); if p<=0.7
A(i,j) = 0;
elseif p>0.7&&p<=0.8 A(i,j) = 1; else
A(i,j) = 4; end end end B = []; for i = 1:20 flag = true; for j = 1:5
if A(i,j)~=0 flag=false; break; end end if ~flag
B = [B;A(i,:)]; end end B
3, (函数文件)对于输入的正整数,判断其是否为素数 function [ output_args ] = u3( n ) %U3 Summary of this function goes here % Detailed explanation goes here y=1;
for i=2:1:sqrt(n) if rem(n,i)==0 y=0; break end end
if(y==1)
fprintf('是素数') else
fprintf('不是素数') end
4,(函数文件)对于输入的正整数,求出其中0的个数; function [ i ] = u4( n )
%U4 Summary of this function goes here % Detailed explanation goes here i=0;
while n/10~=0
if rem(n,10)==0 i=i+1; end
n=fix(n/10); end
5,(函数文件)有n个人围成一圈,按序列编号。从第一个人开始报数,数到m时该人退出,
并且下一个从1开始重新报数,那么最后剩下的那个人的原始编号为多少?(n>m,例如n=20,m=7
function [ x ] = u5( n,m )
%U5 Summary of this function goes here % Detailed explanation goes here x=1:n;
y=zeros(1,n-m+1); t=0;
p=size(x,2);
s=fix(p/m); while s>0 j=1;
while j<=s
y(t+j)=x(m*j); j=j+1; end
x([m:m:m*s])=[]; if m*s
x=x([((m-1)*s+1):(p-s),1:((m-1)*s)]); end t=t+s;
p=size(x,2); s=fix(p/m); end
6, 对曲线 | x^2+y^2+z^2=4
| x+y+z=1 作图,并修饰
ezplot('x^2+y^2+(1-x-y)^2-4',[-2,2,-2,2])
曲面作图:z=x^2+y^2+sin(xy),定义域自拟; x=0:100;y=0:100;
[x,y]=meshgrid(x,y); z=x.^2+y.^2+sin(x.*y); plot3(x,y,z)
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新医药卫生数学建模matlab作业 全文阅读和word下载服务。
相关推荐: