Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 314686

Submitted on 3 Sep 2013 by James

Correct

105Size
Leading solution size is 11.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
eqn='CH4';
mass=atomic_wt(eqn)
assert(isequal(mass,16))
e0 =
    19    24     4
e0g9 =
     1     2
e0g9 =
     2
p =
     1
mass =
    12
e0g9 =
     []
p =
     4
mass =
    16
mass =
    16
2
Pass
 
%%
eqn='O2';
mass=atomic_wt(eqn)
assert(isequal(mass,32))
e0 =
    31     2
e0g9 =
     1
e0g9 =
     []
p =
     2
mass =
    32
mass =
    32
3
Pass
 
%%
eqn='CO2';
mass=atomic_wt(eqn)
assert(isequal(mass,44))
e0 =
    19    31     2
e0g9 =
     1     2
e0g9 =
     2
p =
     1
mass =
    12
e0g9 =
     []
p =
     2
mass =
    44
mass =
    44
4
Pass
 
%%
eqn='C2H6';
mass=atomic_wt(eqn)
assert(isequal(mass,30))
e0 =
    19     2    24     6
e0g9 =
     1     3
e0g9 =
     3
p =
     2
mass =
    24
e0g9 =
     []
p =
     6
mass =
    30
mass =
    30
5
Pass
 
%%
eqn='H2SO4'; % 98
mass=atomic_wt(eqn)
assert(isequal(mass,98))
e0 =
    24     2    35    31     4
e0g9 =
     1     3     4
e0g9 =
     3     4
p =
     2
mass =
     2
e0g9 =
     4
p =
     1
mass =
    34
e0g9 =
     []
p =
     4
mass =
    98
mass =
    98
6
Pass
 
%%
eqn='SO4'; % 96
mass=atomic_wt(eqn)
assert(isequal(mass,96))
e0 =
    35    31     4
e0g9 =
     1     2
e0g9 =
     2
p =
     1
mass =
    32
e0g9 =
     []
p =
     4
mass =
    96
mass =
    96
7
Pass
 
%%
eqn='NO2'; % 46
mass=atomic_wt(eqn)
assert(isequal(mass,46))
e0 =
    30    31     2
e0g9 =
     1     2
e0g9 =
     2
p =
     1
mass =
    14
e0g9 =
     []
p =
     2
mass =
    46
mass =
    46
8
Pass
 
%%
eqn='NO'; % 30
mass=atomic_wt(eqn)
assert(isequal(mass,30))
e0 =
    30    31
e0g9 =
     1     2
e0g9 =
     2
p =
     1
mass =
    14
e0g9 =
     []
p =
     1
mass =
    30
mass =
    30