当前位置:首页 > MATLAB答案
y=[]; for x0=x
if x0<=0
y=[y,sin(x0)]; elseif x0<=3 y=[y,x0]; else
y=[y,-x0+6]; end end
plot(x,y);
axis([-7 7 -2 4]);
title('分段函数曲线'); text(-3*pi/2,1,'y=sin(x)'); text(2,2,'y=x'); text(4,2,'y=-x+6'); 第3题 ua=1;
ub=cos(-2*pi/3)+sin(-2*pi/3)*i; uc=cos(2*pi/3)+sin(2*pi/3)*i;
compass([ua,ub,uc,ua-ub,ub-uc,uc-ua]) title(‘相量图’); 第4题
>> z=0:0.1:4*pi; x=cos(z); y=sin(z);
plot3(x,y,z,'rp');
title('三维空间曲线'); text(0,0,0,'origin');
xlabel('X'),ylabel('Y'),zlabel('Z'); grid; 第5题 (1)
>>x=-3:0.1:3;
[x,y]=meshgrid(x); z=-x.^2/10+y.^2/10; mesh(x,y,z);
xlabel('X'),ylabel('Y'),zlabel('Z'); title('立体网状图'); (2)
>>x=-3:0.1:3;
[x,y]=meshgrid(x); z=-x.^2/10+y.^2/10; surf(x,y,z);
xlabel('X'),ylabel('Y'),zlabel('Z'); title('立体曲面图'); 思考题
>> t=-2*pi:pi/100:2*pi; y1=2.^(0.5*abs(t)); y2=2*exp(-0.2*t); plot(t,y1,'-g'); hold on; plot(t,y2,':r');
legend('曲线y1','曲线y2'); hold off; grid;
实验6
16
第1题
>> A=[3,4,7,2,9,12]; x=roots(A) plot(x,'*'); grid; x =
-0.8612 + 1.4377i -0.8612 - 1.4377i 0.6737 + 1.0159i 0.6737 - 1.0159i -0.9583 第2题
>> A=[1,0,0,0,0,-1]; x=roots(A) plot(x,'*'); grid; x =
-0.8090 + 0.5878i -0.8090 - 0.5878i 0.3090 + 0.9511i 0.3090 - 0.9511i 1.0000 第3题 %估计零点
fplot('x^3+1/x',[0.5,4]); hold on;
fplot('2*x^2*sin(x)-5*x*cos(x)',[0.5,4]); hold off; [m,n]=ginput
%建立函数 function y=f(x)
y=x^3-2*x^2*sin(x)+5*x*cos(x)+1/x;
%调用函数
>> y1=fzero('fz',1.5) y1 =
1.5117
>> y2=fzero('fz',2.5) y2 =
2.6095 第4题 %估计零点 axis([0,1,0,0.1]);
fplot('10^(-12)*exp(Ud*1.6*10^(-19)/(1.38*10^(-23)*300)-1)',[0,4]); hold on;
fplot('(Ud-4)/50',[0,4]); hold off; [m,n]=ginput
%建立函数
function f=myfun(X) Id=X(1); Ud=X(2);
f(1)=Id-10^(-12)*exp(Ud*1.6*10^(-19)/(1.38*10^(-23)*300)-1); f(2)=50*Id-Ud-4;
%调用函数
17
>> x=fsolve('myfun',[0,0.8],optimset('Display','off')) x =
0.0936 0.6795 %验证结果 >> K=myfun(x) K =
1.0e-008 *
-0.3087 0 第5题
>> p=[0.0,1.1,2.1,2.8,4.2,5.0,6.1,6.9,8.1,9.0,9.9]; u=[10,11,13,14,17,18,22,24,29,34,39]; x=polyfit(p,u,3) %得多项式系数 t=linspace(0,10,100); y=polyval(x,t); %求多项式得值 plot(p,u,'*',t,y,'r') %画拟和曲线 x =
0.0195 -0.0412 1.4469 9.8267
实验7 第1题 >>f=50; w=2*pi*f; h=1e-5; tf=40e-3; t=0:h:tf; wt=w*t;
y1=4/pi*sin(wt);
y2=4/pi*(sin(wt)+1/3*sin(3*wt));
y3=4/pi*(sin(wt)+1/3*sin(3*wt)+1/5*sin(5*wt)+1/7*sin(7*wt)+1/9*sin(9*wt));
y4=4/pi*(sin(wt)+1/3*sin(3*wt)+1/5*sin(5*wt)+1/7*sin(7*wt)+1/9*sin(9*wt)+1/11*sin(11*wt)+1/13*sin(13*wt)+1/15*sin(15*wt)+1/17*sin(17*wt)+1/19*sin(19*wt)); y=square(wt); subplot(2,2,1); plot(wt,y1,wt,y); title('1次谐波'); subplot(2,2,2); plot(wt,y2,wt,y); title('1,3次谐波'); subplot(2,2,3); plot(wt,y3,wt,y);
title('1,3,5,7,9次谐波'); subplot(2,2,4); plot(wt,y4,wt,y);
title('1,3,5……,19次谐波'); 第2题 参数如下: >> R=6e-4; C=17e-4; L=6e-9;
模块参数设置:
Integrator1的Initial condition:15kV 在命令窗口为R,L,C赋值。
仿真参数设置如下: Start time:0
Stop time:100e-6
Solver Type:Variable-step
18
Solver:ode45 Max step size:1e-7 Min step size:auto Initial step size:auto Relative tolerance:1e-3 Absolute tolerance:1e-6
19
共分享92篇相关文档