```html
close all;
clear all;
x1 =1:0.01:2;
x2 =1:0.01:2;
y1 = x1.^2;
y2 =sin(2*pi*x2);plot(x1,y1,'-b',x2,y2,'or');legend('x^{2}','sin(2\pix)');xlabel('Time(ms)');ylabel('f(t)');title('Mini Assignment#1');
h =plot(x1,y1);get(gca);
clear all;
close all;
t =(1:1:4)'*pi/2;
x =sin(t);
y =cos(t);fill(x,y,'y');
axis square off;text(0,0,'WAIT','Color','k','Fontsize',60,'FontWeight','bold','HorizontalAlignment','center');%'Fontsize',60 字体大小;'FontWeight','bold' 字体粗度;'HorizontalAlignment','center'%字体居于正中心
clear all;
close all;
x =-2:1:2;
y =-2:1:2;[X,Y]=meshgrid(x,y);
第七节课
clear all;
close all;
guide;
function varargout =P7_test1_1(varargin)% P7_TEST1_1 MATLAB code for P7_test1_1.fig
% P7_TEST1_1, by itself, creates a new P7_TEST1_1 or raises the existing
% singleton*.%% H = P7_TEST1_1 returns the handle to a new P7_TEST1_1 or the handle to
% the existing singleton*.%%P7_TEST1_1('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in P7_TEST1_1.M with the given input arguments.%%P7_TEST1_1('Property','Value',...) creates a new P7_TEST1_1 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before P7_test1_1_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to P7_test1_1_OpeningFcn via varargin.%%*See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run(singleton)".%% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help P7_test1_1
% Last Modified by GUIDE v2.523-Sep-202222:09:56% Begin initialization code - DO NOT EDIT
gui_Singleton =1;
gui_State =struct('gui_Name', mfilename,...'gui_Singleton', gui_Singleton,...'gui_OpeningFcn', @P7_test1_1_OpeningFcn,...'gui_OutputFcn', @P7_test1_1_OutputFcn,...'gui_LayoutFcn',[],...'gui_Callback',[]);if nargin &&ischar(varargin{1})
gui_State.gui_Callback =str2func(varargin{1});
end
if nargout
[varargout{1:nargout}]=gui_mainfcn(gui_State, varargin{:});elsegui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
%--- Executes just before P7_test1_1 is made visible.
function P7_test1_1_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data(see GUIDATA)% varargin command line arguments to P7_test1_1(see VARARGIN)% Choose default command line output for P7_test1_1
handles.output = hObject;% Update handles structure
guidata(hObject, handles);% UIWAIT makes P7_test1_1 wait for user response(see UIRESUME)%uiwait(handles.figure1);%--- Outputs from this function are returned to the command line.
function varargout =P7_test1_1_OutputFcn(hObject, eventdata, handles)% varargout cell array for returning output args(see VARARGOUT);% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data(see GUIDATA)% Get default command line output from handles structure
varargout{1}= handles.output;%--- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)% hObject handle to pushbutton1(see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data(see GUIDATA)%--- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)% hObject handle to pushbutton2(see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data(see GUIDATA)%--- Executes on button press in pushbutton3.
function pushbutton3_Callback(hObject, eventdata, handles)% hObject handle to pushbutton3(see GCBO)% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data(see GUIDATA)
clear all;
close all;
guide;
function varargout = P7_test1_2(varargin)
% P7_TEST1_2 MATLAB code for P7_test1_2.fig
% P7_TEST1_2, by itself, creates a new P7_TEST1_2 or raises the existing
% singleton*.
%
% H = P7_TEST1_2 returns the handle to a new P7_TEST1_2 or the handle to
% the existing singleton*.
%
% P7_TEST1_2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in P7_TEST1_2.M with the given input arguments.
%
% P7_TEST1_2('Property','Value',...) creates a new P7_TEST1_2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before P7_test1_2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to P7_test1_2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help P7_test1_2
% Last Modified by GUIDE v2.5 24-Sep-2022 09:10:57
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @P7_test1_2_OpeningFcn, ...
'gui_OutputFcn', @P7_test1_2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before P7_test1_2 is made visible.
function P7_test1_2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to P7_test1_2 (see VARARGIN)
% Choose default command line output for P7_test1_2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes P7_test1_2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = P7_test1_2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
a = get(handles.slider1,'Value');
b = int16(a);
c = get(handles.slider2,'Value');
d = int16(c);
set(handles.text2,'String',num2str(b+d));
% --- Executes during object creation, after setting all properties.
function slider1_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
% --- Executes on slider movement.
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
a = get(handles.slider1,'Value');
b = int16(a);
c = get(handles.slider2,'Value');
d = int16(c);
set(handles.text2,'String',num2str(b+d));
% --- Executes during object creation, after setting all properties.
function slider2_CreateFcn(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: slider controls usually have a light gray background.
if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor',[.9 .9 .9]);
end
第八节课
clear all;
close all;
I = imread('pout.tif');
I2 = histeq(I);
subplot(1,4,1);
imhist(I);
subplot(1,4,2);
imshow(I);
subplot(1,4,3);
imhist(I2);
subplot(1,4,4);
imshow(I2);
clear all;
close all;
I = imread('rice.png');
subplot(1,2,1);
imshow(I);
%%
%进行旋转遍历
x = 30; %旋转角度
z = [cos(x) -sin(x);sin(x) cos(x)];
for i = 1:size(I,1)
for j = 1:size(I,2)
a = z*[i;j];
b = a(1);
c = a(2);
d = int16(b);
e = int16(c);
I(i,j) = I(d,e);
end
end
subplot(1,2,2);
imshow(I);
第九节课
clear all;
close all;
I = imread('rice.png');
subplot(1,4,1);
imshow(I);
subplot(1,4,2);
imhist(I);
level = graythresh(I);
bw = im2bw(I,level);
subplot(1,4,3);
imshow(bw);
for i = 1:size(I,1)
for j = 1:size(I,2)
if I(i,j)>120
I(i,j) = 255;
else
I(i,j) = 0;
end
end
end
subplot(1,4,4);
imshow(I);
clear all;
close all;
a = [9 -5 3 7];
x = -2:0.01:5;
f = polyval(a,x); %画多元函数图
plot(x,f,'LineWidth',2);
xlabel('x');
ylabel('f(x)');
set(gca,'FontSize',14);
P = [5 0 -2 0 1];
polyder(P); %求微分
b = polyval(polyder(P),7);
clear all;
close all;
a = [20 -7 5 10];
b = [4 12 -3];
x = -2:0.01:1;
m = conv(a,b);
f = polyval(m,x);
z = polyder(m);
f1 = polyval(z,x);
plot(x,f,'-b',x,f1,'-r','LineWidth',2);
xlabel('x');
set(gca,'FontSize',14);
legend('f(x)','f’(x)');
clear all;
close all;
p = [5 0 -2 0 1];
polyint(p,3);
polyval(polyint(p,3),7);
clear all;
close all;
x0 = pi/2;
h = 0.1;
for i = 1:7
x = [x0 x0+h];
y = [sin(x0) sin(x0+h)];
m(i) = diff(y)./diff(x);
h = h/10;
end
clear all;
close all;
g = colormap(lines);
hold on;
for i = 1:3
x = 0:power(10,-i):2*pi;
y = exp(-x).*sin(x.^2/2);
m = diff(y)./diff(x);
plot(x(1:end-1),m,'Color',g(i,:)); %画出3条误差线,在h=0.1,h=0.01,h=0.001情况下
end
hold off;
set(gca,'XLim',[0,2*pi]);
set(gca,'YLim',[-0.3,0.3]);
set(gca,'FontSize',18);
set(gca,'XTick',0:pi/2:2*pi);
set(gca,'XTickLabel',{'0','\pi/2','\pi','3\pi/2','2\pi'});
h = legend('h=0.1','h=0.01','h=0.001');
set(h,'FontName','Times New Roman');
box on;
clear all;
close all;
x = 0:0.01:2*pi;
xy_plot(@sin,x); %对于这种定义的sin,需要加@
y = @(x) 1./(x.^3-2*x-5);
integral(y,0,2);
第十一节课
clear all;
close all;
syms x;
y = cos(x)^2-sin(x)^2;
solve(y,x);
m = cos(x)^2+sin(x)^2;
a = solve(m,x);
%方程式求根
clear all;
close all;
syms x y a b r;
B = solve((x-a)^2+(y-b)^2 - r^2);
syms a b c d;
A = [a b;c d];
C = inv(A); %求逆矩阵
clear all;
close all;
syms x;
y = exp(x^2)/(x^3-x+3);
g = (x^2+x*y-1)/(y^3+x+3);
A = diff(y);
B = diff(g);
clear all;
close all;
syms x;
y = (x^2-x+1)/(x+3);
z = int(y,x,0,10);
clear all;
close all;
syms x y;
fun = @root2d; %定义输入变量F1,F2
x0 = [-5 -5];
A = fsolve(fun,x0);
clear all;
close all;
f = @(x)x.^2; %输入是x,f是x^2
options = optimset('MaxIter',1e3,'TolFun',1e-10); %MaxIter是算迭代次数1e3是10^3,TolFun是误差小于多少,1e-10是10^-10,
a = fsolve(f,0.1,options);
b = fzero(f,0.1,options); %由于x^2,零点相切所以找出答案是NaN
c = roots([1 -3.5 2.75 2.125 -3.875 1.25]); %求高项次方程式的解
第十二节课
clear all;
close all;
A = [1 2 1;2 6 1;1 1 4];
b = [2;7;3];
R = rref([A b]); %对多个线性方程组矩阵化并化简