实验

发布于 2024-05-01  185 次阅读


实验一

x=[]; %定义一个空矩阵,用于存放获得的整数
% ********** Begin ********** % 
for i=1:1000
    if rem(i,13)==2
        x=[x,i];
    end
end
% ********** End ********** % 

disp(num2str(x(20:30)))
%已知变量x和数学函数f,g,用fg和gf分别表示f(g(x))和g(f(x))
pkg load symbolic
% ********** Begin ********** % 
syms x;
f=x*sin(x)/(sqrt(x*x-2)*(x+5));
g=tan(x);
fg=subs(f,x,g);
gf=subs(g,x,f);
% ********** End ********** % 
disp(fg)
disp(gf)
pkg load symbolic
a=sym([1,1]);%a(1)=a(2)=1
%Fibonacci的最高项a(120)
% ********** Begin ********** % 
for i=3:120
    a=[a,a(i-1)+a(i-2)];
end
% ********** End ********** %

disp(a(100:120))
pkg load symbolic
x1=sym(1);
x2=x1/2+3/(2*x1);
e=10^(-14);
syms n;
syms steady_value;
%求取达到e精度的稳态值steady_value和n
% ********** Begin ********** %
for i=2:100
    if double(abs(x1-x2))<e
        n=i;
        steady_value=x2;
        break;
    else
        x1=x2;
        x2=x1/2+3/(2*x1);
    end
end
% ********** End ********** %
disp(num2str(n))
disp(steady_value)
D=str2num(input('','s'));
h=str2num(input('','s'));
x=str2num(input('','s'));
% ********** Begin ********** % 
y=5.*(D==3)+0.1.*(D==10);
% ********** End ********** % 
disp(num2str(y))

实验二

%%%%%%%%%%%%%%%%%%
%请不要修改
warning('off','all');
graphics_toolkit('gnuplot')

%%%%%%%%%%%%%%%%%%

m1=0:0.1:5;
m2=0:0.2:10;
m3=0:0.15:7.5;
y1=cos(m1);
y2=sin(m2);
y3=cos(m1).+sin(m3);
figure (1)
subplot(1,2,1);

%%%%%%%%% Begin %%%%%%%%%
plot(m1,y1,m2,y2,m3,y3);
title('figure 1'); 
%%%%%%%%% End %%%%%%%%%

subplot(1,2,2);

%%%%%%%%% Begin %%%%%%%%%
plotyy(m1,y1,m2,y2);
title('figure 2'); 
%%%%%%%%% End %%%%%%%%%
%用于生成图像,请不要修改
sa=pwd;
print(1,'-djpeg','./picture/step1/picture1.jpg');
run('./task1/test1.m');
system('python3  ./task1/test1py.py');
%%%%%%%%%%%%%%%%%%
%请不要修改
warning('off','all');
graphics_toolkit('gnuplot')

%%%%%%%%%%%%%%%%%%

figure (1)
subplot(1,2,1);

%%%%%%%%% Begin %%%%%%%%%
x=-16:0.5:16;
y=-10:0.5:10;
[X,Y]=meshgrid(x,y);
z=sin(sqrt(X.^2+Y.^2));
mesh(X,Y,z);
%%%%%%%%% End %%%%%%%%%

subplot(1,2,2);

%%%%%%%%% Begin %%%%%%%%%
ezplot('x.^3+y.^3-4*x*y+1/6');
%%%%%%%%% End %%%%%%%%%
%画图显示部分,请不要修改
sa=pwd;
print(1,'-djpeg','./picture/step2/picture2.jpg');
run('./task2/test2.m');
system('python3  ./task2/test2py.py');

实验三

%%%%%%%%%%%%%%%
%%请不要改动
warning('off','all');
graphics_toolkit('gnuplot')
pkg load image
addpath(genpath(pwd));
%%%%%%%%%%%%%%%%%%
figure(1)
%%%%%%%%% Begin %%%%%%%%%
ifelse=@(a,b,c) (a~=0)*b+(a==0)*c;%%定义if-else三目运算符
T=2*pi;
h=@(x,lx,ux) ifelse(x<lx,0,ifelse(x>ux,0,x/(2*T)));
x=(-2*pi):0.1:2*pi;
f=sin(x);
g=zeros(size(x));
for i=1:size(x,2)
  for j=1:size(x,2)
    g(i)=g(i)+f(j)*h(i-j,-1.57,1.57);
  end
end
%%%%%%%%% End %%%%%%%%%
%print(1,'-djpeg','./pictures/step1/picture1.jpg');
%run('./task1/test1.m');
%system('python3  ./task1/test1py.py');

disp(g(1,1:3));
最后更新于 2024-05-01