matlab试题求解
1. %方法一 a=1;b=10;n=100; result = linspace(a,b,n); %方法二 a=1;b=10; result = a:(b-a)/100:b; 2. strA = A1bcDEfijK4; %(1)取第1-5个字符组成字符串 strB = strA(1:5); %(2) 将字符串倒过来重新排列 strC = strA(size(strA,2):-1:1); %(3) 将字符串中的大写字母变成相应的小写字母,其余字符不变 pos = find(strA>=A& strA<=Z); strD = strA; strD(pos) = strD(pos) + 32; %(4) 统计字符串中大写字母的个数。 num = sum(strA >=A & strA <=Z); 3. rand(state,0);A=rand(3,5) %全下标 [i,j] = find(A>.5); %半下标 k = find(A>.5); 4. s=sign(randint(1,1000,[],123)-.5); n=sum(s==-1) 5. clear, format long, rand(state,1), A=rand(3,3); %对角元素 B = diag(diag(A)); %其他元素 C = A - B; 6. function f = myfun(x) f = 3*x^5+5*x^4+x^2+12; %求根 x = fzero(@(x) myfun(x),0.1); %计算f(-1) result = myfun(-1); %计算f(x)+g(x) f1 = sym(3*x^5+5*x^4+x^2+12); g1 = sym(3*x^2+5*x-3); fg1 = f1+g1; fg2 = f1-g1; fg3 = f1*g1; fg4 = f1/g1;
急求这道Matlab试题答案
%old成年兔子,new新生兔子,sum是一个数组,用来存放每个月的兔子数
sum=zeros(1,24);
old=1;new=1;
sum(1)=old+new;
for i=2:24
old=old+new;
new=old;
sum(i)=old+new;
end
sum