⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lg_llagrange.m

📁 拉格朗日差值算法实现
💻 M
字号:
function varargout = lg_llagrange(varargin)
% LG_LLAGRANGE M-file for lg_llagrange.fig
%      LG_LLAGRANGE, by itself, creates a new LG_LLAGRANGE or raises the existing
%      singleton*.
%
%      H = LG_LLAGRANGE returns the handle to a new LG_LLAGRANGE or the handle to
%      the existing singleton*.
%
%      LG_LLAGRANGE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in LG_LLAGRANGE.M with the given input arguments.
%
%      LG_LLAGRANGE('Property','Value',...) creates a new LG_LLAGRANGE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before lg_llagrange_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to lg_llagrange_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

% Copyright 2002-2003 The MathWorks, Inc.

% Edit the above text to modify the response to help lg_llagrange

% Last Modified by GUIDE v2.5 18-Nov-2008 11:21:34

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @lg_llagrange_OpeningFcn, ...
                   'gui_OutputFcn',  @lg_llagrange_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 lg_llagrange is made visible.
function lg_llagrange_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 lg_llagrange (see VARARGIN)

% Choose default command line output for lg_llagrange
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes lg_llagrange wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = lg_llagrange_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 lgBtn.
function lgBtn_Callback(hObject, eventdata, handles)
% hObject    handle to lgBtn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
x=-5:0.1:5;
a=size(x);
n=a(2);
for i=1:n
    y(i)=1/(1+x(i)^2);
end
X=linspace(-5,5,40);
m=length(X);
for i=1:m
    Y(i)=1/(1+X(i)^2);
end
plot(x,y,X,Y,'r*')

% --- Executes on button press in lagBtn.
function lagBtn_Callback(hObject, eventdata, handles)
% hObject    handle to lagBtn (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

x=-5:1:5;
a=size(x);
n=a(2);
for i=1:n
    y(i)=1/(1+x(i)^2);
end
X=linspace(-5,5,40);
m=length(X);
Y=zeros(1,m);
for k=1:m
   s=0;
    for i=1:n
      o=1;
         for j=1:n
            if i~=j
              
              o=o*((X(k)-x(j))/(x(i)-x(j)));
            end
         end
        
       s=s+y(i)*o;
    end
    Y(k)=s;
   
end
plot(x,y,X,Y)



% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject    handle to open (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
file = uigetfile('*.fig');
if ~isequal(file, 0)
    open(file);
end


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


% --------------------------------------------------------------------
function close_Callback(hObject, eventdata, handles)
% hObject    handle to close (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
                     ['Close ' get(handles.figure1,'Name') '...'],...
                     'Yes','No','Yes');
if strcmp(selection,'No')
    return;
end

delete(handles.figure1)


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -