2024年4月25日发(作者:苟慧心)
基本操作
-5/(4.8+5.32)^2
area=pi*2.5^2
x1=1+1/2+1/3+1/4+1/5+1/6
exp(acos(0.3))
a=[1 2 3;4 5 6;7 8 9]
a=[1:3,4:6,7:9]
a1=[6: -1:1]
a=eye(4) a1=eye(2,3) b=zeros(2,10) c=ones(2,10) c1=8*ones(3,5)
d=zeros(3,2,2);
r1=rand(2, 3)
r2=5-10*rand(2, 3)
r4=2*randn(2,3)+3
arr1=[1.1 -2.2 3.3 -4.4 5.5]
arr1(3) arr1([1 4]) arr1(1:2:5)
arr2=[1 2 3; -2 -3 -4;3 4 5]
arr2(1,:)
arr2(:,1:2:3)
arr3=[1 2 3 4 5 6 7 8]
arr3(5:end) arr3(end)
绘图
x=[0:1:10];
y=x.^2-10*x+15;
plot(x,y)
x=0:pi/20:2*pi
y1=sin(x);y2=cos(x);
plot(x,y1,'b-');
hold on;
plot(x,y2,‘k--’);
legend (‘sin x’,‘cos x’);
x=0:pi/20:2*pi;
y=sin(x);
figure(1)
plot(x,y, 'r-')
grid on
以二元函数图 z = xexp(-x^2-y^2) 为例讲解基本操作,首先需要利用meshgrid函数生
成X-Y平面的网格数据,如下所示:
xa = -2:0.2:2;
ya = xa;
[x,y] = meshgrid(xa,ya);
z = x.*exp(-x.^2 - y.^2);
mesh(x,y,z);
建立M文件
function fenshu( grade )
if grade > 95.0
disp('The grade is A.');
else
if grade > 86.0
disp('The grade is B.');
else
if grade > 76.0
disp('The grade is C.');
else
if grade > 66.0
disp('The grade is D.');
2024年4月25日发(作者:苟慧心)
基本操作
-5/(4.8+5.32)^2
area=pi*2.5^2
x1=1+1/2+1/3+1/4+1/5+1/6
exp(acos(0.3))
a=[1 2 3;4 5 6;7 8 9]
a=[1:3,4:6,7:9]
a1=[6: -1:1]
a=eye(4) a1=eye(2,3) b=zeros(2,10) c=ones(2,10) c1=8*ones(3,5)
d=zeros(3,2,2);
r1=rand(2, 3)
r2=5-10*rand(2, 3)
r4=2*randn(2,3)+3
arr1=[1.1 -2.2 3.3 -4.4 5.5]
arr1(3) arr1([1 4]) arr1(1:2:5)
arr2=[1 2 3; -2 -3 -4;3 4 5]
arr2(1,:)
arr2(:,1:2:3)
arr3=[1 2 3 4 5 6 7 8]
arr3(5:end) arr3(end)
绘图
x=[0:1:10];
y=x.^2-10*x+15;
plot(x,y)
x=0:pi/20:2*pi
y1=sin(x);y2=cos(x);
plot(x,y1,'b-');
hold on;
plot(x,y2,‘k--’);
legend (‘sin x’,‘cos x’);
x=0:pi/20:2*pi;
y=sin(x);
figure(1)
plot(x,y, 'r-')
grid on
以二元函数图 z = xexp(-x^2-y^2) 为例讲解基本操作,首先需要利用meshgrid函数生
成X-Y平面的网格数据,如下所示:
xa = -2:0.2:2;
ya = xa;
[x,y] = meshgrid(xa,ya);
z = x.*exp(-x.^2 - y.^2);
mesh(x,y,z);
建立M文件
function fenshu( grade )
if grade > 95.0
disp('The grade is A.');
else
if grade > 86.0
disp('The grade is B.');
else
if grade > 76.0
disp('The grade is C.');
else
if grade > 66.0
disp('The grade is D.');