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

📄 jfk2.asv

📁 电磁辐射的数值分析与仿真(基于MATLAB语言)。包括两个点电荷的电场
💻 ASV
📖 第 1 页 / 共 2 页
字号:
function varargout = jfk2(varargin)
% JFK2 M-file for jfk2.fig
%      JFK2, by itself, creates a new JFK2 or raises the existing
%      singleton*.
%
%      H = JFK2 returns the handle to a new JFK2 or the handle to
%      the existing singleton*.
%
%      JFK2('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in JFK2.M with the given input arguments.
%
%      JFK2('Property','Value',...) creates a new JFK2 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before jfk2_OpeningFunction gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to jfk2_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 jfk2

% Last Modified by GUIDE v2.5 27-Apr-2005 15:56:52
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @jfk2_OpeningFcn, ...
                   'gui_OutputFcn',  @jfk2_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin & isstr(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 jfk2 is made visible.
function jfk2_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 jfk2 (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = jfk2_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 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, change%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.usewhitebg = 1;if usewhitebg    set(hObject,'BackgroundColor',[.9 .9 .9]);else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- 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% --- 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, change%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.usewhitebg = 1;if usewhitebg    set(hObject,'BackgroundColor',[.9 .9 .9]);else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));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% --- Executes during object creation, after setting all properties.function slider3_CreateFcn(hObject, eventdata, handles)% hObject    handle to slider3 (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, change%       'usewhitebg' to 0 to use default.  See ISPC and COMPUTER.usewhitebg = 1;if usewhitebg    set(hObject,'BackgroundColor',[.9 .9 .9]);else    set(hObject,'BackgroundColor',get(0,'defaultUicontrolBackgroundColor'));end% --- Executes on slider movement.function slider3_Callback(hObject, eventdata, handles)% hObject    handle to slider3 (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% --- Executes during object creation, after setting all properties.function pop1_CreateFcn(hObject, eventdata, handles)% hObject    handle to pop1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    empty - handles not created until after all CreateFcns called% Hint: popupmenu 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% --- Executes on selection change in pop1.function pop1_Callback(hObject, eventdata, handles)% hObject    handle to pop1 (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 pop1 contents as cell array%        contents{get(hObject,'Value')} returns selected item from pop1

% --- Executes during object creation, after setting all properties.
function pop2_CreateFcn(hObject, eventdata, handles)                                                                                                   
% hObject    handle to pop2 (see GCBO)                                                                                                             
% eventdata  reserved - to be defined in a future version of MATLAB                                                                                         
% handles    empty - handles not created until after all CreateFcns called                                                                               
                                                                                                                                                     
% Hint: popupmenu 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                                                                                                                                                        
                                                                                                                                                         

% --- Executes on selection change in pop2.                                                                                                                                                
function pop2_Callback(hObject, eventdata, handles)                                                                                                        
% hObject    handle to pop2 (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 pop2 contents as cell                                                                                         
%                                                                                                                                                                          
% array                                                                     
%                                                                                                                                                    
%        contents{get(hObject,'Value')} returns selected item from pop2
% --- Executes on button press in push1.function push1_Callback(hObject, eventdata, handles)% hObject    handle to push1 (see GCBO)% eventdata  reserved - to be defined in a future version of MATLAB% handles    structure with handles and user data (see GUIDATA)

p1=get(handles.pop1,'Value');
p2=get(handles.pop2,'Value');
s2=get(handles.slider2,'Value');
s3=get(handles.slider3,'Value');

if p1==1
   q=2e-6;k=9e9;a=0.9;b=0;
   x1=-s2:0.1:s2;y1=x1;
   [X1,Y1]=meshgrid(x1,y1);
   rp1=sqrt((X1-a).^2+(Y1-b).^2);rm1=sqrt((X1+a).^2+(Y1+b).^2);
   V1=q*k*(1./rp1-1./rm1);
   [Ex1,Ey1]=gradient(-V1);
   AE1=sqrt(Ex1.^2+Ey1.^2);Ex1=Ex1./AE1;Ey1=Ey1./AE1;
   cv1=linspace(min(min(V1)),max(max(V1)),49);
   axes(handles.axes1);
   if p2==1
       contourf(X1,Y1,V1,cv1,'k-');axis([-s2 s2 -s2 s2]);
       axis('square');hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==2
       quiver(X1,Y1,Ex1,Ey1,0.7);axis([-s2 s2 -s2 s2]);
       axis('square');
       hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
  elseif p2==3
       contourf(X1,Y1,V1,cv1,'k-');axis([-s2 s2 -s2 s2]);
       axis('square');
       hold on;
       quiver(X1,Y1,Ex1,Ey1,0.7);
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
 end
 x2=-s3:20:s3;y2=x2;
   [X2,Y2]=meshgrid(x2,y2);
   rp2=sqrt((X2-a).^2+(Y2-b).^2);rm2=sqrt((X2+a).^2+(Y2+b).^2);
   V2=q*k*(1./rp2-1./rm2);
   [Ex2,Ey2]=gradient(-V2);
   AE2=sqrt(Ex2.^2+Ey2.^2);Ex2=Ex2./AE2;Ey2=Ey2./AE2;
   cv2=linspace(min(min(V2)),max(max(V2)),400);
   axes(handles.axes2);
   if p2==1
       contourf(X2,Y2,V2,cv2,'k-');axis([-s3 s3 -s3 s3]);
       axis('square');hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==2
       quiver(X2,Y2,Ex2,Ey2,0.7);axis([-s3 s3 -s3 s3]);
       axis('square');
       hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==3
       contourf(X2,Y2,V2,cv2,'k-');axis([-s3 s3 -s3 s3]);
       axis('square');
       hold on;
       quiver(X2,Y2,Ex2,Ey2,0.7);
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   end
elseif p1==2
   q=2e-6;k=9e9;a=0.9;b=0;
   x1=-s2:0.1:s2;y1=x1;
   [X1,Y1]=meshgrid(x1,y1);
   rp1=sqrt((X1-a).^2+(Y1-b).^2);rm1=sqrt((X1+a).^2+(Y1+b).^2);
   V1=q*k*(1./rp1+1./rm1);
   [Ex1,Ey1]=gradient(-V1);
   AE1=sqrt(Ex1.^2+Ey1.^2);Ex1=Ex1./AE1;Ey1=Ey1./AE1;
   cv1=linspace(min(min(V1)),max(max(V1)),49);
   axes(handles.axes1);
   if p2==1
       contourf(X1,Y1,V1,cv1,'k-');axis([-s2 s2 -s2 s2]);
       axis('square');hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==2
       quiver(X1,Y1,Ex1,Ey1,0.7);axis([-s2 s2 -s2 s2]);
       axis('square');
       hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
  elseif p2==3
       contourf(X1,Y1,V1,cv1,'k-');axis([-s2 s2 -s2 s2]);
       axis('square');
       hold on;
       quiver(X1,Y1,Ex1,Ey1,0.7);
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
 end
 x2=-s3:20:s3;y2=x2;
   [X2,Y2]=meshgrid(x2,y2);
   rp2=sqrt((X2-a).^2+(Y2-b).^2);rm2=sqrt((X2+a).^2+(Y2+b).^2);
   V2=q*k*(1./rp2+1./rm2);
   [Ex2,Ey2]=gradient(-V2);
   AE2=sqrt(Ex2.^2+Ey2.^2);Ex2=Ex2./AE2;Ey2=Ey2./AE2;
   cv2=linspace(min(min(V2)),max(max(V2)),100);
   axes(handles.axes2);
   if p2==1
       contourf(X2,Y2,V2,cv2,'k-');axis([-s3 s3 -s3 s3]);
       axis('square');hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==2
       quiver(X2,Y2,Ex2,Ey2,0.7);axis([-s3 s3 -s3 s3]);
       axis('square');
       hold on;
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   elseif p2==3
       contourf(X2,Y2,V2,cv2,'k-');axis([-s3 s3 -s3 s3]);
       axis('square');
       hold on;
       quiver(X2,Y2,Ex2,Ey2,0.7);
       plot(a,b,'wo',a,b,'w-');
       plot(-a,-b,'wo',-a,-b,'w+');
       xlabel('x');ylabel('y');hold off;
   end
end

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

⌨️ 快捷键说明

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