平抛运动
clear;clc;figure
vx =50; %初速度
t =0:0.001:10; %时间向量
x = vx*t; %x方向
y =-9.8*t.^2/2; %y方向
comet(x,y) %
clear;clc;figure
vx =100*cos(1/4*pi);
vy =100*sin(1/4*pi);
t =0:0.001:15;
x = vx*t;
y =vy*t-9.8*t.^2/2;
comet(x,y)
clear;clc;
dt=0.1;t1=0:dt:4*pi
vx=2
vy=sin(t1)
x=vx.*t1
y=1-cos(t1)
figure;
plot(t1,vy)
grid on;axis equal;
figure;
comet(x,y)
grid on;axis equal
Matlab语言学习
微分,diff 例如
syms x;
diff(x^2+cos(x))
结果: ans = 2*x - sin(x)
还可以求n阶导数,diff(y,n)
syms x;
y=x^2+cos(x)
diff(y,2)
%ans = 2 - cos(x)
求积分
syms x;
int(exp(x)-3*cos(x))
% ans = exp(x) - 3*sin(x)
计算y=sin(x),x从0到pi
syms x;
int(sin(x),0,pi)
% ans =2
matlab如何画两个图,用plot命令的时候
https://www.cnblogs.com/haore147/p/3633017.html
https://blog.csdn.net/xkl7111/article/details/17223617
hold on;就可以啦,然图像保持不被替代。
在同一个窗口画两张图的话,用subplot,例:
figure(1);
subplot(1,2,1);
plot(…);
subplot(1,2,2);
plot(…);
在不同的窗口中画两张图,用figure,例:
figure(1);
plot(…);
figure(2);
plot(…);
弧度角度
matlab中算的三角函数都是弧度,其实很多专业软件都是用弧度来表示,我们在使用过程中需要注意这一点。简单的加个d搞定。
改刻度;
figure;
axes;
axis([0 100 0 1000])
set(gca,'XTick',0:20:100);
set(gca,'YTick',0:200:1000);
按比例输出图像坐标轴 axis equal
x = linspace(0,8*2000, 10000);
y=400*sin(2*pi*x/2000)
plot(x,y)
axis equal
matlab逻辑判断。
a = input('输入一个数:');
b = input('输入一个数:');
if a > 2 && b <= 7
disp('a > 2 && b <= 7');
else
disp('否(a > 2 && b <= 7)');
end
求a中小于4的集合。
a=[18,2,3,23,5,6]
c=a(a>4)