当前位置:首页 > matlab答案
(4)
[x,y,z] = sphere; %等价于sphere(20) 20是画出来的球面的经纬分面数...20的话就是20个经度, 20个纬度,或者说“就是划出20╳20面的单位球体,把球的表面分成400个小网格”
surf(x,y,z); %绘制单位球面 x = 10*x; y = 10*y; z = 10*z;
surf(x,y,z); %绘制半径为10的球面 axis equal
3.在同一图形窗口中采用子图形式分别绘制正方形、圆、三角形和六边形。 答:
n=[3 4 6 2^10] for i=1:4
subplot(2,2,i)
theta=linspace(pi/n(i),2*pi+pi/n(i),n(i)+1); plot(cos(theta),sin(theta)); axis equal; end
4. 分别用plot和fplot绘制下列分段函数的曲线。
?x2?41?x?5,x?0?f(x)??0,x?0
?x3?1?x?5,x?0?答:
plot函数: 方法一:
x=linspace(-10,10,200); y=[]; for x0=x if x0>0
y=[y,x0.^2+(1+x0).^(1/4)+5]; elseif x0==0 y=[y,0]; elseif x0<0
y=[y,x0.^3+sqrt(1-x0)-5]; end end
plot(x,y)
方法二:
x=linspace(-10,10,200);
y=(x<0).*(x.^3+sqrt(1-x)-5)+(x==0).*0+(x>0).*(x.^2+(1+x).^(1/4)+5); plot(x,y)
用fplot函数:
fplot('(x<0).*(x.^3+sqrt(1-x)-5)+(x==0).*0+(x>0).*(x.^2+(1+x).^(1/4)+5)',[-10,10])
5. 在同一坐标轴中绘制下列两条曲线并标注两曲线的交叉点。 (1)y?2x?0.5
?x?sin(3t)cost?0?t?? (2)??y?sin(3t)sint?答: 相邻两点x1、x2 曲线(1)相应的y值为y11、y12, 曲线(2)y相应的y值y21、y22, 若(y11-y21)与(y12-y22)符号相反或等于0,则x1或x2就是一个交叉点。 方法一:
t=linspace(0,pi,300); x=sin(3*t).*cos(t); y1=2*x-0.5;
y2=sin(3*t).*sin(t); len=length(t); p=y1-y2;
x3=x((find(p(1:len-1).*p(2:len)<=0))); y3=2*x3-0.5;
plot(x,y1,x,y2,x3,y3,'rd')
方法二:用循环 %t=0:0.01:pi;
t=linspace(0,pi,100); x=sin(3*t).*cos(t); y1=2*x-0.5;
y2=sin(3*t).*sin(t); plot(x,y1,x,y2);grid; delta_y=y1-y2;
% figure;stem(delta_y); j=1;
for i=1:length(t)-1
if delta_y(i)*delta_y(i+1)<=0 position(j)=i+1; j=j+1; end end hold on;
plot(x(position),y1(position),'ro'); title('两条曲线相交'); xlabel('x');ylabel('y'); h = legend('y1','y2');
共分享92篇相关文档