Write a MATLAB program to generate a table of the base-10 logarithms between 1 and 10 in steps of \(0.1\). The table should start on a new page, and it should include a title describing the table and row and column headings. This table should be organized as shown below.

Short Answer

Expert verified
Here's the short answer based on the step-by-step solution: To create a MATLAB program that generates a table of base-10 logarithms from 1 to 10 in steps of 0.1, we'll use the following code: ``` % Create an array of numbers from 1 to 10 with a step size of 0.1 X = linspace(1, 10, 91); % Calculate the base-10 logarithms of the numbers in the array logValues = log10(X); % Print title and column headers fprintf('\n\nBase-10 logarithm table from 1 to 10\n'); fprintf('-------------------------------------\n'); fprintf(' Number Logarithm\n'); % Display the table with the desired format for i = 1:length(X) fprintf('%6.2f %9.6f\n', X(i), logValues(i)); end ``` This code creates an array of numbers from 1 to 10, calculates their base-10 logarithms, and then organizes and displays the results in a table as specified in the question.

Step by step solution

01

Create an array of numbers from 1 to 10 with a step size of 0.1

To create an array of numbers from 1 to 10 with a step size of 0.1, we can use the built-in MATLAB function `linspace()`. The syntax of this function is `linspace(start, end, num_points)` where `start` is the starting value, `end` is the ending value and `num_points` is the number of equally spaced points between the start and end values. In our case, we want a step size of 0.1, so we will have 91 equally spaced points between 1 and 10 as follows: `X = linspace(1, 10, 91);`
02

Calculate the base-10 logarithms of the numbers in the array

To calculate the base-10 logarithms of the numbers in the array `X`, we can use the MATLAB function `log10()` which computes the element-wise base-10 logarithm of the input array. The syntax for this function is `log10(X)` where X is an array of numbers. In our case, we will apply the `log10()` function to our array `X` and store the result in a new array called `logValues` as follows: `logValues = log10(X);`
03

Create the table with the desired format

To create a table with the desired format in MATLAB, we can use the following functions and commands: 1. `table(X, logValues, 'VariableNames', {'Numbers', 'Logarithms'})`: This creates a table with two columns, `Numbers` and `Logarithms`, and fills them with the values from the array `X` and `logValues`, respectively. 2. `display(T)`: This displays the table created by the `table()` function in the MATLAB command window. Here is how we can create the table in our MATLAB code: `T = table(X, logValues, 'VariableNames', {'Numbers', 'Logarithms'}); display(T);`
04

Add the title and organize the output

To add the title and organize the output, we can use the `fprintf()` function. This function allows us to include a custom title, column headers, and page breaks. In our case, we will add a title, row, and column headers using the following commands: ``` fprintf('\n\nBase-10 logarithm table from 1 to 10\n'); fprintf('-------------------------------------\n'); fprintf(' Number Logarithm\n'); ``` To display the table, we can make use of the `fprintf()` function again within a loop that iterates through the table and prints out each row: ``` for i = 1:length(X) fprintf('%6.2f %9.6f\n', X(i), logValues(i)); end ```
05

Final MATLAB code

Here is the complete MATLAB code that accomplishes the given task: ``` % Step 1: Create an array of numbers from 1 to 10 with a step size of 0.1 X = linspace(1, 10, 91); % Step 2: Calculate the base-10 logarithms of the numbers in the array logValues = log10(X); % Step 4: Add the title and organize the output fprintf('\n\nBase-10 logarithm table from 1 to 10\n'); fprintf('-------------------------------------\n'); fprintf(' Number Logarithm\n'); % Step 3: Display the table with the desired format T = table(X, logValues, 'VariableNames', {'Numbers', 'Logarithms'}); for i = 1:length(X) fprintf('%6.2f %9.6f\n', X(i), logValues(i)); end ```

Unlock Step-by-Step Solutions & Ace Your Exams!

  • Full Textbook Solutions

    Get detailed explanations and key concepts

  • Unlimited Al creation

    Al flashcards, explanations, exams and more...

  • Ads-free access

    To over 500 millions flashcards

  • Money-back guarantee

    We refund you if you fail your exam.

Over 30 million students worldwide already upgrade their learning with Vaia!

One App. One Place for Learning.

All the tools & learning materials you need for study success - in one app.

Get started for free

Most popular questions from this chapter

Angles are often measured in degrees \(\left({ }^{\circ}\right)\), minutes \(\left({ }^{*}\right)\), and seconds \(\left({ }^{*}\right)\), with 360 degrees in a circle, 60 minutes in a degree, and 60 seconds in a minute. Write a program that reads angles in radians from an input disk file, and converts them into degrees, minutes, and seconds. Test your program by placing the following four angles expressed in radians into an input file, and reading that file into the program: \(0.0,1.0,3.141593,6.0\).

Write a program to read a set of integers from an input data file, and locate the largest and smallest values within the data file. Print out the largest and smallest values, together with the lines on which they were found. Assume that you do not know the number of values in the file before the file is read.

What is the difference between binary and formatted \(1 / O\) ? Which MATLAB functions perform each type of L/O?

We wrote a MATLAB program that calculated the arithmetic mean (average), rms average, geometric mean, and harmonic mean for a set of numbers. Modify that program to read an arbitrary number of values from an input data file, and calculate the means of those numbers. To test the program, place the following values into an input data file and run the program on that file: \(1.0,2.0,5.0,4.0,3.0\), \(2.1,4.7,3.0\).

The acceleration due to the Earth's gravity at any height \(h\) above the surface of the Earth is given by the equation $$ g=-G \frac{M}{(R+h)^{2}} $$ where \(G\) is the gravitational constant \(\left(6.672 \times 10^{-11} \mathrm{~N} \mathrm{~m}^{2} / \mathrm{kg}^{2}\right), M\) is the mass of the Earth \(\left(5.98 \times 10^{24} \mathrm{~kg}\right), R\) is the mean radius of the Earth \((6371 \mathrm{~km})\), and \(h\) is the height above the Earth's surface. If \(M\) is measured in \(\mathrm{kg}\) and \(R\) and \(h\) in meters, then the resulting acceleration will be in units of meters per second squared. Write a program to calculate the acceleration due to the Earth's gravity in \(500-\mathrm{km}\) increments at heights from \(0 \mathrm{~km}\) to \(40,000 \mathrm{~km}\) above the surface of the Earth. Print out the results in a table of height versus acceleration with appropriate labels, including the units of the output values. Plot the data as well.

See all solutions

Recommended explanations on Psychology Textbooks

View all explanations

What do you think about this solution?

We value your feedback to improve our textbook solutions.

Study anywhere. Anytime. Across all devices.

Sign-up for free