You are on page 1of 7

function varargout = jacobi(varargin)

% JACOBI M-file for jacobi.fig


% JACOBI, by itself, creates a new JACOBI or raises the existing
% singleton*.
%
% H = JACOBI returns the handle to a new JACOBI or the handle to
% the existing singleton*.
%
% JACOBI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in JACOBI.M with the given input arguments.
%
% JACOBI('Property','Value',...) creates a new JACOBI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before jacobi_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to jacobi_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 jacobi

% Last Modified by GUIDE v2.5 26-Sep-2009 19:24:42

% Begin initialization code - DO NOT EDIT


gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @jacobi_OpeningFcn, ...
'gui_OutputFcn', @jacobi_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 jacobi is made visible.


function jacobi_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 jacobi (see VARARGIN)
set(handles.A_edit,'String','[0.98 -0.05 -0.02;-0.04 -0.9 0.07;-0.02 0.09 0.94]');
set(handles.b_edit,'String','[1;1;1]');
set(handles.x0_edit,'String','[0;0;0]');
set(handles.eps_edit,'String','1.0e-6');
set(handles.M_edit,'String','8');
% Choose default command line output for jacobi
handles.output = hObject;

% Update handles structure


guidata(hObject, handles);

% UIWAIT makes jacobi wait for user response (see UIRESUME)


% uiwait(handles.figure1);

% --- Outputs from this function are returned to the command line.
function varargout = jacobi_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;

function A_edit_Callback(hObject, eventdata, handles)


% hObject handle to A_edit (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 A_edit as text


% str2double(get(hObject,'String')) returns contents of A_edit as a double

% --- Executes during object creation, after setting all properties.


function A_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to A_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function b_edit_Callback(hObject, eventdata, handles)


% hObject handle to b_edit (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 b_edit as text


% str2double(get(hObject,'String')) returns contents of b_edit as a double

% --- Executes during object creation, after setting all properties.


function b_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to b_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function x0_edit_Callback(hObject, eventdata, handles)


% hObject handle to x0_edit (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 x0_edit as text


% str2double(get(hObject,'String')) returns contents of x0_edit as a double

% --- Executes during object creation, after setting all properties.


function x0_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to x0_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function eps_edit_Callback(hObject, eventdata, handles)


% hObject handle to eps_edit (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 eps_edit as text


% str2double(get(hObject,'String')) returns contents of eps_edit as a double

% --- Executes during object creation, after setting all properties.


function eps_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to eps_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function M_edit_Callback(hObject, eventdata, handles)
% hObject handle to M_edit (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 M_edit as text


% str2double(get(hObject,'String')) returns contents of M_edit as a double

% --- Executes during object creation, after setting all properties.


function M_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to M_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function x_edit_Callback(hObject, eventdata, handles)


% hObject handle to x_edit (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 x_edit as text


% str2double(get(hObject,'String')) returns contents of x_edit as a double

% --- Executes during object creation, after setting all properties.


function x_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to x_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function n_edit_Callback(hObject, eventdata, handles)


% hObject handle to n_edit (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 n_edit as text


% str2double(get(hObject,'String')) returns contents of n_edit as a double

% --- Executes during object creation, after setting all properties.


function n_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to n_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- 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 yunxing.


function yunxing_Callback(hObject, eventdata, handles)
% hObject handle to yunxing (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
A=str2num(get(handles.A_edit,'String'));
b=str2num(get(handles.b_edit,'String'));
x0=str2num(get(handles.x0_edit,'String'));
eps=str2num(get(handles.eps_edit,'String'));
M=str2num(get(handles.M_edit,'String'));

[x,n]=yakebi(A,b,x0,eps,M);

set(handles.x_text,'String',strcat(num2str(x)));
set(handles.n_edit,'String',strcat(num2str(n)));

% --- Executes on button press in guanbi.


function guanbi_Callback(hObject, eventdata, handles)
% hObject handle to guanbi (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

close

function [x,n]=yakebi(A,b,x0,eps,M)
if nargin==3
eps= 1.0e-6;
M = 10000;
elseif nargin ==4
M =10000;
end

D=diag(diag(A)); %A
L=-tril(A,-1); %A
U=-triu(A,1); %A
B=D\(L+U);
f=D\b;
x=x0;
n=0;
tol=1;
x=x';
while tol>=eps
x=x';
x=B*x0+f;
n=n+1;
tol=norm(x-x0);
x0=x;
x=x';
if(n>=M)
return;
end
end

% --- Executes on selection change in listbox4.


function listbox4_Callback(hObject, eventdata, handles)
% hObject handle to listbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox4 contents as cell array


% contents{get(hObject,'Value')} returns selected item from listbox4

% --- Executes during object creation, after setting all properties.


function listbox4_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

function out_edit_Callback(hObject, eventdata, handles)


% hObject handle to out_edit (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 out_edit as text


% str2double(get(hObject,'String')) returns contents of out_edit as a double

% --- Executes during object creation, after setting all properties.


function out_edit_CreateFcn(hObject, eventdata, handles)
% hObject handle to out_edit (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 && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

% --- Executes on selection change in listbox5.

function listbox5_Callback(hObject, eventdata, handles)


% hObject handle to listbox5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)

% Hints: contents = get(hObject,'String') returns listbox5 contents as cell array


% contents{get(hObject,'Value')} returns selected item from listbox5

% --- Executes during object creation, after setting all properties.


function listbox5_CreateFcn(hObject, eventdata, handles)
% hObject handle to listbox5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called

% Hint: listbox controls usually have a white background on Windows.


% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'),
get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end

You might also like