Advertisement
Guest User

other team code

a guest
Oct 23rd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. >> a=.142; %Bond length in nanometers
  2. locations=[];
  3.  
  4. %get user inputs
  5. prompt = 'What is the length of the sheet in the X direction in nanometers? X:';
  6. length=input(prompt);
  7. prompt = 'What is the length of the sheet in the Y direction in nanometers? Y:';
  8. height=input(prompt);
  9.  
  10. %setting the starting heights for the 4 rows
  11. r1=0;
  12. r2=a/2;
  13. r3=3/2*a;
  14. r4=2*a;
  15.  
  16. while(true)
  17.  
  18. %Row 1
  19. if(r1>height)
  20. break;
  21. end
  22. x=0;
  23. %Adding points from this row to the matrix
  24. while(x<=length)
  25. str="C\t"+x+"\t"+r1+"\t"+0;
  26. locations=[locations;str];
  27. x=x+a*sqrt(3);
  28. end
  29. r1=r1+3*a;
  30.  
  31.  
  32. %Row 2
  33. if(r2>height)
  34. break;
  35. end
  36. x=a/2*sqrt(3);
  37. %Adding points from this row to the matrix
  38. while(x<=length)
  39. str="C\t"+x+"\t"+r2+"\t"+0;
  40. locations=[locations;str];
  41. x=x+a*sqrt(3);
  42. end
  43. r2=r2+3*a;
  44.  
  45.  
  46. %Row 3
  47. if(r3>height)
  48. break;
  49. end
  50. x=a/2*sqrt(3);
  51. %Adding points from this row to the matrix
  52. while(x<=length)
  53. str="C\t"+x+"\t"+r3+"\t"+0;
  54. locations=[locations;str];
  55. x=x+a*sqrt(3);
  56. end
  57. r3=r3+3*a;
  58.  
  59.  
  60. %Row 4
  61. if(r4>height)
  62. break;
  63. end
  64. x=0;
  65. %Adding points from this row to the matrix
  66. while(x<=length)
  67. str="C\t"+x+"\t"+r4+"\t"+0;
  68. locations=[locations;str];
  69. x=x+a*sqrt(3);
  70. end
  71. r4=r4+3*a;
  72.  
  73. end
  74.  
  75. %Finding number of carbon atoms
  76. eh=size(locations);
  77. numloc=eh(1);
  78.  
  79. %Setting file to print out the points to
  80. fid=fopen('graphene.xyz','wt');
  81.  
  82. %Beginning of the file formatting
  83. fprintf(fid,""+numloc+"\n\n");
  84.  
  85. %Printing each point from matrix to xyz file named 'graphene.xyz' in the correct formatting
  86. for i=1:numloc
  87. fprintf(fid,locations(i)+"\n");
  88. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement