Skip to content

YlmzCmlttn

Cemalettin Yılmaz Blog

Menu
  • Home
  • About Me
  • Projects
    • Iot-AR
    • Magnifi-AR
    • Smarthome-IOS
    • Others
  • Categories
    • Articles
    • Augmented Reality
    • Capture The Flag
      • Google CTF
        • 2018
    • Embedded Systems
    • IoT
    • Logisim
    • My Essays
    • Nvidia Jetson
      • Jetson TX1
    • Operating Systems
      • Kali
      • Raspbian
      • Ubuntu
    • Personal
    • Programming
      • Arduino
      • C
      • C#
      • Css
      • Html
      • Js
      • Matlab
      • Node.js
      • Python
      • Swift
      • VHDL
    • Projects
      • Embedded Systems
      • Electric
      • IoT
      • IoT-AR
      • Logisim
      • Magnifi-AR
      • Pose Estimation
    • Raspberry Pi
    • Xilinx
    • Others
Menu

Files: Periodic Table – Electron Configurations | Matlab Examples

Posted on November 26, 2018February 20, 2019 by Yılmaz Cemalettin

Matlab Tutorials | Examples

Practice 11:

Files: Periodic Table – Electron Configurations

You are given a file named “PeriodicTable.txt”. The format of the file is as follows:

The third column of this file, electron configuration, gives the arrangement of the electrons in various atomic orbitals around the nucleus. For simplicity, the configuration gives a noble gas symbol (in square brackets) plus the orbitals that need to be added on top of it.

Write a MATLAB program that does the following jobs:

  1. Reads the entire periodic table file into variable(s).
    1. A pop-up file selection dialog box should be displayed for choosing the TXT file to be read from.
    2. You should check for errors that might occur while opening the file. If the filer dialog box is cancelled, stop the program. If there is any error while opening the file, an explanation describing the nature of the error should be printed into the command window, and the program should be terminated.
    3. The first line of the file is a header line, and should be skipped.
    4. You can decide to read the file into any kind of variable—matrix, record structure array, cell array.
    5. You should assume that number of lines in the file changes as more elements are added; so you should not assume a fixed number of lines in the file, but rather read the file until end-of-file.
  2. Expand the electron configurations of all atoms, and determine the atomic number for each by adding up the electron counts in all s, p, d, and f atomic orbitals. Note that atomic number of an element is NOT equal to its sequence in our list, as some elements are omitted from the given file.
  3. In your list of chemical elements, add a string field to describe the group of the element. For elements that belong to the groups Alkali Metals, Alkali Earth Metals, Halogens, and Noble Gases, change their group value to “A”, “E”, “H”, and “N”, respectively; for all others, leave this value as blank.
    1. Noble gases have six electrons in outermost p-orbital (except Helium, which you should include as an exceptional noble gas).
    2. Alkali metals follow noble gases in atomic number.
    3. Alkali earth metals follow alkali metals in atomic number.
    4. Halogens come just before noble gases in atomic number. Note that Hydrogen is an exception to this rule; it is not a Halogen.

4. From
Earth Metals, Halogens, Noble Gases into four separate files in your MATLAB work folder. Four fields should be written into the output file in tabular format: Symbol, element name, atomic number, and expanded electron configuration. Files should be named as follows (no need to ask for their names):

your list of elements, write those that belong to the groups Alkali Metals, Alkali

Group

File name

Alkali Metals

Group1A.txt

Alkali Earth Metals

Group2A.txt

Halogens

Group7A.txt

Noble Gases

Group8A.txt

The file Group1A.txt should be laid out exactly as follows. The other individual raw data files (Group2A.txt, Group7A.txt, Group8A.txt) should have similar format as Group1A.txt.

 

Files:https://drive.google.com/open?id=1lLHt_BW1z3f2XNUuMncKpTPKGbj86LGF

Solutions:

MATLAB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
clear
clc
fclose all;
j=1;
a=1;
b=1;
c=1;
d=1;
flag1=false;
flag2=false;
% Open input file
 
[file,folder]= uigetfile('*.txt','Select input file'); % Get the name of txt file from user
if file==0
    return
end
[fin,err]= fopen([folder file],'r'); % Open file for read
if fin==-1
    disp(err);
    return
end
[fout1,err]= fopen('Group1A.txt','w');% Open files for write
if fout1==-1
    disp(err);
    fclose all;
    return
end
[fout2,err]= fopen('Group2A.txt','w');
if fout2==-1
    disp(err);
    fclose all;
    return
end
[fout7,err]= fopen('Group7A.txt','w');
if fout7==-1
    disp(err);
    fclose all;
    return
end
[fout8,err]= fopen('Group8A.txt','w');
if fout8==-1
    disp(err);
    fclose all;
    return
end
fgetl(fin);
fprintf(fout1,'Group 1A\r\n%-7s%-12s%-5s  %s\r\n','SYMBOL','NAME','Atom#','ELECTRON CONFIGURATION');
fprintf(fout2,'Group 2A\r\n%-7s%-12s%-5s  %s\r\n','SYMBOL','NAME','Atom#','ELECTRON CONFIGURATION');
fprintf(fout7,'Group 7A\r\n%-7s%-12s%-5s  %s\r\n','SYMBOL','NAME','Atom#','ELECTRON CONFIGURATION');
fprintf(fout8,'Group 8A\r\n%-7s%-12s%-5s  %s\r\n','SYMBOL','NAME','Atom#','ELECTRON CONFIGURATION');
while ~feof(fin) % read file until end of file
    x= fgetl(fin);
    i= 1;
    sum = 0;
    while x(i)~=' ' % read symbol
        i= i+1;
    end
    electron(j).symbol= x(1:i-1);
    i2= 8;
    while x(i2)~=' ' % read element name
        i2= i2+1;
    end
    electron(j).name= x(8:i2-1);
    i3= 23;
    electron(j).configuration= x(23:end);
    if electron(j).configuration == "1s2" % Select first two condition because they are different than others
        group8(a).symbol = electron(j).symbol(1:end); %Initilaze the helium in group8
        group8(a).name = electron(j).name(1:end);
        group8(a).configuration = electron(j).configuration(1:end); %Save in the structure
        splitted = strsplit(group8(a).configuration,'.');
        for count=1:length(splitted)
            sum = sum +str2num(splitted{1,count}(3:end)); % Calculate electron numbers
        end
        fprintf(fout8, '%-7s%-12s%5g  %s\r\n',group8(a).symbol ,group8(a).name,sum,group8(a).configuration);
        a = a +1;
        flag1= true;
    elseif electron(j).configuration == "1s1"  % Select first two condition because they are different than others
        group7(b).symbol = electron(j).symbol(1:end);%Initilaze the hydrogen in group7
        group7(b).name = electron(j).name(1:end);
        group7(b).configuration = electron(j).configuration(1:end);%Save in the structure
        splitted = strsplit(group7(b).configuration,'.');
        for count=1:length(splitted)
            sum = sum +str2num(splitted{1,count}(3:end));% Calculate electron numbers
        end
        fprintf(fout7, '%-7s%-12s%5g  %s\r\n',group7(b).symbol ,group7(b).name,sum,group7(b).configuration);
        b = b +1;
    elseif electron(j).configuration(end-1:end) == 'p6' %Find if configuration finish with p6 it is 8A
        group8(a).symbol = electron(j).symbol(1:end);
        group8(a).name = electron(j).name(1:end);
        group8(a).configuration = [group8(end-1).configuration electron(j).configuration(5:end)]; %%Find full configuration use above group8A elements configuration
        splitted = strsplit(group8(a).configuration,'.');
        for count=1:length(splitted)
            sum = sum + str2num(splitted{1,count}(3:end));
        end
        fprintf(fout8, '%-7s%-12s%5g  %s\r\n',group8(a).symbol ,group8(a).name,sum,group8(a).configuration);
        a = a +1;
        flag1= true;
    elseif electron(j).configuration(end-1:end) == 'p5'
        group7(b).symbol = electron(j).symbol(1:end);
        group7(b).name = electron(j).name(1:end);
        group7(b).configuration = [group8(end).configuration electron(j).configuration(5:end)];%%Find full configuration use above group8A elements configuration
        splitted = strsplit(group7(b).configuration,'.');
        for count=1:length(splitted)
            sum = sum + str2num(splitted{1,count}(3:end)); %Calculate totoal electron
        end
        fprintf(fout7, '%-7s%-12s%5g  %s\r\n',group7(b).symbol ,group7(b).name,sum,group7(b).configuration);
        b = b +1;
    elseif flag1 %%IF 8A group found flag1 is true so that after 8A is 1A.
        group1(c).symbol = electron(j).symbol(1:end);
        group1(c).name = electron(j).name(1:end);
        group1(c).configuration = [group8(end).configuration electron(j).configuration(5:end)];
        splitted = strsplit(group1(c).configuration,'.');
        for count=1:length(splitted)
            sum = sum + str2num(splitted{1,count}(3:end));
        end
        fprintf(fout1,'%-7s%-12s%5g  %s\r\n',group1(c).symbol ,group1(c).name,sum,group1(c).configuration);
        c = c +1;
        flag1=false;
        flag2=true; %Preparation for the 2A
    elseif flag2 %%IF 1A group found flag1 is true so that after 1A is 2A.
        group2(d).symbol = electron(j).symbol(1:end);
        group2(d).name = electron(j).name(1:end);
        group2(d).configuration = [group8(end).configuration electron(j).configuration(5:end)];
        splitted = strsplit(group2(d).configuration,'.');
        for count=1:length(splitted)
            sum = sum + str2num(splitted{1,count}(3:end));
        end
        fprintf(fout2,'%-7s%-12s%5g  %s\r\n',group2(d).symbol ,group2(d).name,sum,group2(d).configuration);
        d = d +1;
        flag2=false;
    end
    j = j+1;
end
fclose all;
disp('Done');

 

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

My Motto

“Learn to share, Share to learn”

LinkedIn Badge

Cemalettin Yılmaz

Ads

Archives

Categories

  • Articles (1)
  • Augmented Reality (3)
  • Capture The Flag (23)
    • Google CTF (22)
      • 2018 (13)
      • 2019 (9)
    • PicoCTF (1)
      • 2019 (1)
  • Embedded Systems (3)
  • IoT (3)
  • Logisim (1)
  • My Essays (3)
  • Nvidia Jetson (5)
    • Xavier (5)
  • Operating Systems (24)
    • Kali (3)
    • Raspbian (2)
    • Ubuntu (21)
  • Others (1)
  • Personal (1)
  • Programming (44)
    • Arduino (4)
    • C (10)
    • C# (4)
    • C++ (5)
    • Css (1)
    • CUDA (6)
    • Html (1)
    • Js (2)
    • Libraries (5)
      • OpenCV (3)
      • OpenGL (2)
    • Matlab (14)
    • Node.js (5)
    • Python (6)
    • Swift (3)
  • Programs (4)
    • Tools (4)
  • Projects (21)
    • Books Solutions (8)
    • Electric (2)
    • Embedded Systems (2)
    • Energy Harvesting (1)
    • IoT (2)
    • IoT-AR (1)
    • Logisim (1)
    • Magnifi-AR (3)
    • Pose Estimation (3)
    • Smarthome-Ios (1)
  • Raspberry Pi (3)
  • Uncategorized (2)
  • YZlib (1)

Recent Posts

  • atof stof stod problems with local floating point separator in C/C++
  • Pico CTF 2019 Answers
  • YZlib: Personal C++ Library
  • Drive to target | Google CTF 2019
  • FriendSpaceBookPlusAllAccessRedPremium | Google CTF 2019

Recent Comments

  • AbaShelha on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Peter on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • Yılmaz Cemalettin on 16-Bit CPU on Logisim
  • Jenny on 16-Bit CPU on Logisim
  • MOON on 16-Bit CPU on Logisim
  • anti on Ghidra Installation on Ubuntu |18.04, 16.04, 14.04
  • hunkerjr on STOP GAN | Google CTF 2019
  • Shaq on 16-Bit CPU on Logisim
  • NURUL AFIQAH MOHD HASBULLAH on 16-Bit CPU on Logisim

Linkedln

© 2022 YlmzCmlttn | Powered by Superbs Personal Blog theme