1.分段函数
for x=-pi*6:pi/10:6*pi
y=sin(x);
if y<0
y=0;
end
fprintf('x=%f,y=%f',x,y);
end
2.计算距离
x1=input('enter the x1:' );
y1=input('enter the y1:' );
x2=input('enter the x2:' );
y2=input('enter the y2:' );
d=sqrt((x1-x2).^2+(y1-y2).^2);
fprintf('the distance of the two points is :%f',d);
v0=input('Enter the 初速度 v0:');
h0=input('Enter the 离地高度 h0:');
t=0:0.01:5
3.重力加速度
h=-0.5*9.81*t.^2+v0*t+h0;
v=-9.81*t+v0;
plot(t,h,'k-',t,v,'b--');
title(' Plot of h(t) and v(t)');
xlabel('t');
ylabel('h(t)andv(t)');
legend('h(t)','v(t)');
4.坐标转换
function [x, y] = polar2rect(r, theta)
x = r * cos(theta * pi/180);
y = r * sin(theta * pi/180);