Question

In: Computer Science

Write a Matlab script which creates two vectors from the table below; pne vector for the...

Write a Matlab script which creates two vectors from the table below; pne vector for the element names and a second for element atomic numbers. Print the statement "[element name] has an odd atomic number: [element atomic number]." for each element with an odd atomic number.

Element Atomic Number
Gold 79
Carbon 6
Hydrogen 1
Oxygen 8
Sodium 11
  • Use a for loop.
  • Use a if statement.
  • Print one statement per line.
  • Use the mod function when testing for odd atomic numbers.

Solutions

Expert Solution

element.m

% Initialize both vectors with elements name and atomic number
element_name = {"Gold","Carbon","Hydrogen","Oxygen","Sodium"};
atomic_number = [79 6 1 8 11];

% Iterate loop over array
% If atomic number is not divisibe by 2, its odd
% Print element name and its atomic number
for i = 1:length(element_name)
if mod(i,2)!= 0
fprintf('%s has an odd atomic number: %d ',element_name{i},atomic_number(i));
end
end

SCREENSHOT-

OUTPUT-


Related Solutions

2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with...
2. Vector Element Calculation Write a MATLAB script which will randomly generate a 20-element vector with integer values ranging between −100 to +100. Using LOOP command, determine the number of negative elements in the vector. For example, given A = [15 −6 0 -8 −2 5 4 −10 -3 −5], the number of negative numbers are 6.
Write a Matlab script that computes the element level stiffness matrix and force vector for linear...
Write a Matlab script that computes the element level stiffness matrix and force vector for linear elasticity.
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of...
USING MATLAB write a script that creates eight subplots(4x2). In each one, graph the values of sin(n(pi)x), where -1 <=x<=1, with an interval of 0.05 for n = 1 to 8. there is no parenthesis on pi. I just didn't want to make it look like (npix) so it wouldn't be confusing to read.
Write a script named numberlines.py. This script creates a program listing from a source program. This...
Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the user for the names of two files. The input filename could be the name of the script itself, but be careful to use a different output filename! The script copies the lines of text from the input file to the output file, numbering each line as it goes. The line numbers should be right-justified in 4 columns, so that the...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one...
USING MATLAB Where indicated in the script below, write a function, called myflip, which accepts one vector v (either a column or a row) and outputs the same vector v of the same dimensions, but with the values in reverse order (use MATLAB function flip()). In other words, v will be overwritten by its flipped version. In your function, you may only use length() and floor(). You only need one loop. %this code tests the function, myflip, which you will...
Write a MATLAB script which gets a matrix as input and check the dimensions of the...
Write a MATLAB script which gets a matrix as input and check the dimensions of the input: Part A) If the input matrix is a square matrix, calculate the inverse of it and show it in the command window, otherwise, show the text “the input matrix is not invertible”. Part B) Reshape the input matrix to a row vector and assign it to Y and make a vector named X with the same length as Y then make a 2D...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program,...
MATLAB: Write as a script in the editor window of matlab. Quadratic roots. Write a program, quadroots.m, for finding the roots of the second- order polynomial ax2 + bx + c. Use the quadratic equation. The inputs are the coefficients a,b, and c and the outputs are z1 and z2. The program should produce (exactly) the following output in the Command window when run with (a, b, c) = (1, 2, −3):
Im writing a matlab script called vecadd that deals with vectors and is converting them between...
Im writing a matlab script called vecadd that deals with vectors and is converting them between polar and rectangular coordinates. It is supposed to function based upon the following parameters: vecadd adds two vectors and outputs the resultant vector. vecadd(A,B) assumes A and B are both in rectangular form. The first element of each vector is the "x" component and the second element is the "y" component. The resultant is output in rectangular form. vecadd(A,B,'p') assumes A and B are...
MATLAB Write a script which asks the user of the program to provide an initial horizontal...
MATLAB Write a script which asks the user of the program to provide an initial horizontal position, initial vertical position, initial velocity, and angle. Create a time vector spanning from zero seconds to 100 seconds incremented at 0.01 seconds. Call the function that you created in the previous problem to calculate the trajectory and velocities of the projectile. Find the maximum height of the projectile and the time at which it reaches that point. Write a neat sentence stating what...
9.) Write a MATLAB script that will read the Pressure and Temperature columns from the provided...
9.) Write a MATLAB script that will read the Pressure and Temperature columns from the provided Excel file. Use a loop to calculate the linear best fit line for the data. You may only use the built-in functions sum, size, and length. Plot both the individual data points (red) and the fit line (blue) on the same graph. Include a title and axes labels.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT