📄 zxp.m
字号:
set(handles.edit5,'string',time);
set(handles.edit7,'string',ess);
axes(handles.axes1);
cla;
t=0:0.001:1;
yy=feval(fun1,t);
plot(t,yy,x,y,'o')
% --- Executes during object creation, after setting all properties.function edit4_CreateFcn(hObject, eventdata, handles)% hObject handle to edit4 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit4_Callback(hObject, eventdata, handles)% hObject handle to edit4 (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,'String') returns contents of edit4 as text% str2double(get(hObject,'String')) returns contents of edit4 as a double% --- Executes during object creation, after setting all properties.function edit5_CreateFcn(hObject, eventdata, handles)% hObject handle to edit5 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit5_Callback(hObject, eventdata, handles)% hObject handle to edit5 (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,'String') returns contents of edit5 as text% str2double(get(hObject,'String')) returns contents of edit5 as a doublefunction [y,x,time,count]=quanju(fun,a,b,delta)
size=(b-a)/delta
y_min=feval(fun,a);
x_min=a;
k=0;
tic
for i=1:size
if y_min>feval(fun,a+i*delta)
y_min=feval(fun,a+i*delta);
x_min=a+i*delta;
end
k=k+1;
end
time=toc;
count=k;
y=y_min;
x=x_min;
function [y,x,time,count]=seperate(fun1,fun2,a,b,delta)
size=(b-a)/delta;
k=1;
c=(a+b)/2;
tic
while k<size
if feval(fun2,a)*feval(fun2,c)<0
b=c;
c=(a+b)/2;
elseif feval(fun2,c)*feval(fun2,b)<0
a=c;
c=(a+b)/2;
else
x=c;
break
end
k=k+1;
end
time=toc;
count=k;
x=c;
y=feval(fun1,x);
function [y,x,time,count]=fabonacci(fun,a,b,delta,dt)
if dt>0.5
dt=1-dt;
end
size=(b-a)/delta;
t1=a+dt*(b-a);
t2=a+b-t1;
k=1;
tic
while k<size
if feval(fun,t1)>feval(fun,t2)
if b-t1<delta
x=t2;
break;
else
a=t1;
t1=t2;
t2=a+(1-dt)*(b-a);
k=k+1;
end
else
if t2-a<delta
x=t1;
break
else
b=t2;
t2=t1;
t1=a+dt*(b-a);
k=k+1;
end
end
end
count=k;
time=toc;
y=feval(fun,x);
function [y,x,time,count]=golden(fun,a,b,delta)
size=(b-a)/delta;
t1=a+0.382*(b-a);
t2=a+b-t1;
k=1;
tic
while k<size
if feval(fun,t1)>feval(fun,t2)
if b-t1<delta
x=t2;
break;
else
a=t1;
t1=t2;
t2=a+0.618*(b-a);
k=k+1;
end
else
if t2-a<delta
x=t1;
break
else
b=t2;
t2=t1;
t1=a+0.382*(b-a)
k=k+1;
end
end
end
count=k;
time=toc;
y=feval(fun,x);% --- Executes on button press in pushbutton10.function pushbutton10_Callback(hObject, eventdata, handles)% hObject handle to pushbutton10 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)axes(handles.axes1);
cla;
set(handles.edit1,'string',[0.0001]);
set(handles.edit3,'string',[0]);
set(handles.edit4,'string',[0]);
set(handles.edit5,'string',[0]);
set(handles.edit7,'string',[0])
set(handles.edit6,'visible','off','string',[0.618]);
set(handles.text11,'visible','off');
function edit6_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc
set(hObject,'BackgroundColor','white');
else
set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));
end
function edit3_Callback(hObject, eventdata, handles)
% hObject handle to edit3 (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,'String') returns contents of edit3 as text
% str2double(get(hObject,'String')) returns contents of edit3 as a double
% --- Executes during object creation, after setting all properties.function edit7_CreateFcn(hObject, eventdata, handles)% hObject handle to edit7 (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles empty - handles not created until after all CreateFcns called% Hint: edit controls usually have a white background on Windows.% See ISPC and COMPUTER.if ispc set(hObject,'BackgroundColor','white');else set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));endfunction edit7_Callback(hObject, eventdata, handles)% hObject handle to edit7 (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,'String') returns contents of edit7 as text% str2double(get(hObject,'String')) returns contents of edit7 as a double
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -