Hi everyone.
I am creating a GUI program. I chose a vector lambda and found 2 vector wich variable is lambda.
To to this I use sym. I creat an equation and matlab derive it analytically twice.
But when I want to creat an exe. with the compiler, sym can't be use….Do you know an alternative?
The first I know is to do numerical derivation, but their is a loose of precision.
Regards
function Simuclose all% f=figure('units','normalized','outerposition',[0 0 1 1]);
% f=figure('WindowState','fullscreen');
f=figure,set(gcf,'position',[100 100 500 500])%%%%%%%%%%%%%%%%%%%Laser param
dim = [.2 .5 .3 .3];Lx=0.5Ly=1/12str = 'Thickness[nm]';annotation('textbox','String',str,'FitBoxToText','on','Position',[0.0 0.95-2*Ly Lx 2*Ly]);edit1= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0 0.95-2*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','680');str2 = 'Radius[µm]';annotation('textbox',dim,'String',str2,'FitBoxToText','on','Position',[0.0+Lx 0.95-2*Ly Lx 2*Ly]);edit2= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-2*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','28');str3 = 'Lambda_{ini}[nm]';annotation('textbox',dim,'String',str3,'FitBoxToText','on','Position',[0.0 0.95-4*Ly Lx 2*Ly]);edit3= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0 0.95-4*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','800');str4 = 'Lambda_{end}[nm]';annotation('textbox',dim,'String',str4,'FitBoxToText','on','Position',[0.0+Lx 0.95-4*Ly Lx 2*Ly]);edit4= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-4*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','1200');%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
str9 = 'Gas';annotation('textbox',dim,'String',str9,'FitBoxToText','on','Position',[0.0 0.95-6*Ly Lx 2*Ly]);edit9= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0 0.95-6*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','0');listbox1 = uicontrol('Style','listbox','Units', 'normal','Position',[0.0 0.95-6*Ly Lx Ly],'Max',6,'String',{'Air';'Argon';'Xenon'}) ;str10 = 'P(bar)';annotation('textbox',dim,'String',str10,'FitBoxToText','on','Position',[0.0+Lx 0.95-6*Ly Lx 2*Ly]);edit10= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0+Lx 0.95-6*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','1');str11 = 'Number of point ';annotation('textbox',dim,'String',str11,'FitBoxToText','on','Position',[0.0 0.95-8*Ly Lx 2*Ly]);edit11= uicontrol( 'Style', 'edit','Units', 'normal','Position',[0.0 0.95-8*Ly Lx Ly],'FontSize', 15,'BackgroundColor', 'white',... 'String','200');PushButton = uicontrol(gcf,'Style', 'push', 'String', 'Run','Units', 'normal','Position',[0.0 0.95-10*Ly Lx 2*Ly],'CallBack', @PushB);PushButton2 = uicontrol(gcf,'Style', 'push', 'String', 'Stop','Units', 'normal','Position',[0.0 0.95-12*Ly Lx 2*Ly],'CallBack', @endLoop); function endLoop(hObject,eventdata,handles) handles.endLoop=true; guidata(hObject, handles); end%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function [] = PushB(hObject,eventdata,handles) % val = str2num(char(get(edit11,'String')));
edi1 = str2num(char(get(edit1,'String'))); edi2 = str2num(char(get(edit2,'string'))); edi3= str2num(char(get(edit3,'string'))); edi4 =str2num(char(get(edit4,'string'))); edi9 =str2num(char(get(edit9,'string'))); edi10 = str2num(char(get(edit10,'string'))); edi11 = str2num(char(get(edit11,'string'))); index_selected = get(listbox1,'Value'); list = get(listbox1,'String'); gas = list{index_selected}; gas; %% a=2.405*2.405; c=3e8; rc=edi2.*1e-6; %en m
t=edi1.*1e-9;% en m
n_g=1.45; Pression_bar=edi10; Pression_Pa=Pression_bar*1e5; %%%%% (Pa) %%%%%%%
Pression_atm=101325; pgas=Pression_bar *1e5; nbr=edi11; L_start=edi3 ; L_stop= edi4 ; A1=0.05792105; A2=238.0185; B1=0.00167917; B2=57.362; C1=0; C2=0; lamb = sym('lamb') ; ngas= 1 + pgas/101325.* ( (A1 ./ (A2-(lamb.*1e6).^-2) ) + (B1 ./ (B2-(lamb.*1e6).^-2) ) + (C1 ./ (C2-(lamb.*1e6).^-2) )); %ARGON
epsi= n_g.^2 ./ ngas.^2; k_0= 2*pi./(lamb); phi = k_0*t* sqrt(n_g.^2-ngas.^2) ; A=a./( 2.*ngas .*(k_0.*rc).^2); B=a./ ( ngas.^2 .*(k_0.*rc).^3 ); C = epsi; D = 0.5 .* (C+1) ./ sqrt(C-1); nef= ngas - A - B.*D.*cot(phi); dn = diff(nef,lamb); dn2 = diff(dn,lamb); dn3 = diff(dn2,lamb); beta2=lamb.^3.*dn2./(2*pi*c.^2); beta3=-lamb.^4./(2*pi*c).^2 .*(3.*dn2./c + lamb.*dn3./c); lambb=linspace(800,1200,nbr).*1e-9; tic h=waitbar(0, ['Number of point computed :' num2str(0) '/' num2str(nbr)]); for i=1:length(lambb)% close (h)
GVD(i)=double(subs(beta2,lambb(i))); TOD(i)=double(subs(beta3,lambb(i))); NEFF(i)=double(subs(nef,lambb(i))); waitbar(i./length(lambb),h,['Number of point computed :' num2str(i) '/' num2str(nbr)]) hold on end figure plot(lambb.*1e9,GVD.*1e30) title('GVD [fs²/m]') xlabel('Wavelength (nm)') ylabel('GVD (fs²/m)') figure, plot(lambb.*1e9,TOD.*1e45) title('TOD [fs^{3}/m]') xlabel('Wavelength (nm)') ylabel('TOD (fs^{3}/m)') toc ALLDATA(:,1)=lambb.*1e9; ALLDATA(:,2)=NEFF; ALLDATA(:,3)=GVD.*1e30; ALLDATA(:,4)=TOD.*1e45; text= {'Lambda (nm)','Neff','GVD (fs²/m)','TOD (fs^{3}/m'}; ALLDATA2=[text ; num2cell(ALLDATA)]; Filename=datestr(now,'mmmm-dd-yyyy HH-MM'); Filename= ['R=' num2str(edi2) 'µm-t=' num2str(edi1) 'nm-' num2str(edi10) 'bar-' gas ]; writecell(ALLDATA2, [Filename '.txt']) endend
Best Answer