matlab课程实验,实验报告三
时间:2025-07-08
时间:2025-07-08
matlab课程实验,实验报告三
实验三
1.
2.用If语句时:
3.(1)
用switch语句:
matlab课程实验,实验报告三
4. 5.
1.(1)循环
实验四 (2)向量
matlab课程实验,实验报告三
2
(2)
4.
f1=1;f2=0;f3=1;
f=[f1,f2,f3];
for n=4:100
f4=f3-2*f2+f1;
f=[f f4];
f1=f2;f2=f3;f3=f4;
maxvalue=max(f);
minvalue=min(f);
sumvalue=sum(f);
zhengshu=length(find(f>0));
fushu=length(find(f<0));
zeroshu=length(find(f==0)); 3(1)
matlab课程实验,实验报告三
end
maxvalue
minvalue
sumvalue
zhengshu
fushu
zeroshu
maxvalue =4.3776e+011
minvalue =-8.9941e+011
sumvalue =-7.4275e+011
zhengshu =49
fushu =49
zeroshu =2
5sushu=[];
for n=2:49
x=n*(n+1)-1;
signx=0;
for k=2:floor(x/2)
if (mod(x,k)==0)
sign x=1;
end
end
if sign x==0
qqinmishudui=[sushu n n+1]
end
end
qinmishudui
1.函数文件如下:
function F=f(x)
F(1)=exp(x);
F(2)=log(x);
F(3)=sin(pi/180*x); 实验五
F(4)=cos(pi/180*x);
disp(['复数的指数是:',num2str(F(1))])
disp(['复数的对数是:',num2str(F(2))])
disp(['复数的正弦是:',num2str(F(3))])
disp(['复数的余弦是:',num2str(F(4))])
matlab课程实验,实验报告三
2.函数文件
function [X]=s(m1,m2,b)
A=[m1*cos(b),-m1,-sin(b),0;m1*sin(b),0,cos(b),0;0,m2,-sin(b),0;0,0,-cos(b),1]; B=[0;m1*9.8;0;m2*9.8];
X=A\B
3.函数文件
function jueduisushu
k=0;A=[];B=[];s=1;
for a=10:99
sign=0;
for n=2:fix(a/2)
if rem(a,n)==0
sign=1;
end
end
if sign==0
A=[A,a];
k=k+1;
end
end
for s=1:k
sign1=0;
a=A(s);
b=fix(a/10)+rem(a,10)*10;
for n=2:fix(a/2)
if rem(a,n)==0
sign1=1;
end
matlab课程实验,实验报告三
end
if sign1==0
B=[B,a];
end
s=s+1;
end
B
4.函数文件
function F=fx(x)
F=1./((x-2).^2+0.1)+1./((x-3).^4+0.01);
5.函数文件
(1)function F=f1(n)
F=n+10*log(n*n+5);
(2)function F=f2(n)
sum=0;
for i=1:n
F=sum+n*(n+1);
end
实验六
1.绘制曲线
x=0:2*pi/100:2*pi;
y=(0.5+(3*sin(x)/(1+x.^2)))*cos(x);
plot(x,y)
matlab课程实验,实验报告三
2.按要求绘制图形
(1).x=0:pi/100:2*pi;
y1=x.^2;
y2=cos(2*x);
y3=y1.*y2;
plot(x,y1,'b-',x,y2,'k-',x,y3,'r-');
(2)x=0:pi/100:2*pi;
y1=x.^2; y2=cos(2*x); y3=y1.*y2;
subplot(3,1,1); plot(x,y1);
subplot(3,1,2); plot(x,y2);
subplot(3,1,3);
plot(x,y3);
(3).x=0:0.5:10;
y1=x.^2;
y2=cos(2*x*pi/180);
y3=y1.*y2;
subplot(3,4,1);bar(x,y1,'g');title('bar(x,y1,"g")'); subplot(3,4,2);stairs(x,y1,'r');title('stairs(x,y1,"r")'); subplot(3,4,3);stem(x,y1,'k');title('stem(x,y1,"k")'); subplot(3,4,4);fill(x,y1,'b');title('fill(x,y1,"b")'); subplot(3,4,5);bar(x,y2,'g');title('bar(x,y2,"g")'); subplot(3,4,6);stairs(x,y2,'r');title('stairs(x,y2,"r")'); subplot(3,4,7);stem(x,y2,'k');title('stem(x,y2,"k")'); subplot(3,4,8);fill(x,y2,'b');title('fill(x,y2,"b")'); subplot(3,4,9);bar(x,y3,'g');title('bar(x,y3,"g")');
subplot(3,4,10);stairs(x,y3,'r');title('stairs(x,y3,"r")');
matlab课程实验,实验报告三
subplot(3,4,11);stem(x,y3,'k');title('stem(x,y3,"k")'); subplot(3,4,12);fill(x,y3,'b');title('fill(x,y3,"b")');
3.绘制分段函数曲线
x=-5.0:0.1:5.0;
if x>=-5.0&x<=0
y=(x+sqrt(pi))/exp(2);
else
y=1/2*log(x+sqrt(1+x.^2));
end
plot(x,y)
4.利用极坐标绘制曲线
a=input('Enter a:');
b=input('Enter b:');
n=input('Enter n:');
theta=0:0.01:2*pi;
rho=a*sin(b+n*theta);
polar(theta,rho,'p');
Enter a:1 Enter b:2 Enter n:3
Enter a:3 Enter b:6
Enter n:5
…… 此处隐藏:880字,全部文档内容请下载后查看。喜欢就下载吧 ……上一篇:八年级上英语unit9练习题
下一篇:工程有关人员质量责任书