Guest

Tim Waters

By: a guest on Jul 27th, 2009  |  syntax: None  |  size: 2.26 KB  |  hits: 14  |  expires: Never
download  |  raw  |  embed  |  report abuse
Copied
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %For the blog 'Brute Force Physics' by Tim Waters
  3. %filename:stationary.m
  4. %reference: Feynman Lectures 26-4
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6.  
  7. clear all; %clears all variables
  8. close all; %closes all figures
  9.  
  10. eps= .00001 %input('Enter the tick-size (epsilon) ');
  11. n1 = 1 %input('Enter the index of refraction in region containing A ');
  12. n2 = 1.33 %input('Enter the index of refraction in region containing B ');
  13. mirror_axis = 0:eps:1; %cut (0,1) into grid points
  14. c = mirror_axis'; %creates a column vector
  15. a = ones(length(c),1)*rand; %ones(rows,columns) returns a matrix of 1s
  16. b = ones(length(c),1)*rand; %rand gives a random scalar in (0,1)
  17.  
  18. %Compute the optical path length, opl
  19. d_ac = sqrt(a.^2 + c.^2);
  20. d_cb = sqrt((1-c).^2 + b.^2);
  21. opl_ac=n1*d_ac;
  22. opl_cb=n2*d_cb;
  23. opl = opl_ac + opl_cb;
  24.  
  25. opl_min = min(opl);
  26. while opl(i.html">i)~= opl_min
  27.     i.html">i = i.html">i+1;
  28. end
  29. % i now contains the location of opl_min in the vector opl
  30.  
  31. %**************************************************************************
  32. %numerical analysis
  33. m = a(1)+b(1); %slope of straiht line path connecting a to -b
  34. i_ab=floor((a(1)/m)/eps); %vector index of straight line path
  35. x_ab = a(1)/m;
  36. plot(c,opl) %plots opl vs. x
  37. hold on
  38. %place a black * at the straight line path location:
  39. plot(x_ab,opl(i_ab),'k*')
  40. %label it
  41. text(x_ab,opl(i_ab),...
  42.      ' \leftarrow Straight line opl',...
  43.      'EdgeColor','black',...
  44.      'LineWidth',1,...
  45.      'LineStyle',':');
  46. plot(c(i.html">i),opl(i.html">i),'r*')
  47. text(c(i.html">i),opl(i.html">i),...
  48.      ' \leftarrowMinimum opl',...
  49.      'EdgeColor','red',...
  50.      'LineWidth',1,...
  51.      'LineStyle',':');
  52.  
  53.  %compute the 1st and 2nd derivatives around the two points
  54.  [dx_c,ddx_c]=variation(opl,i.html">i,eps); %for point c
  55.  [dx,ddx]=variation(opl,i_ab,eps);
  56.  title({'Numerical Analysis: 1st and 2nd Derivatives:';
  57.   sprintf('1st variation at point c = %0.5f ',dx_c);
  58.   sprintf('2nd variation at point c = %0.5g ',ddx_c);
  59.   sprintf('1st variation at straight line path = %0.5g ',dx);
  60.   sprintf('2nd variation at straight line path = %0.5g ',ddx)})
  61.  
  62. xlabel({sprintf('Straight line opl = %0.5g ',opl(i_ab));
  63.     sprintf('Minimum opl = %0.5g ',opl(i.html">i))});
  64. hold off