Question

In: Mechanical Engineering

Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n'...

Matlab script that uses loops to create a multiplication table (matrix) where the user enters 'n' (nxn chart).

Solutions

Expert Solution

number = input('Enter the number you want the multiplication table to be created');

for i = [1:20]
    fprintf('%d x %d = %d\n',number,i,number*i);
end

Save this program as multiplication_table.m

function generate_table(number)

%this function will generate a multiplication table

for i = [1:20]
    fprintf('%d x %d = %d\n',number,i,number*i);
end
end

Save this program as generate_table.m

(1:10)' * (1:10) 
%Type this in command prompt
for i = (1:10)
    for j = (1:10)
        fprintf('%d\t',i*j);
    end
    fprintf('\n');
end

Save this program as table_multiplication.m

Finally type table_multiplication in command prompt, you get following output of multiplication table:

1 2 3 4 5 6 7 8 9 10

2 4 6 8 10 12 14 16 18 20

3 6 9 12 15 18 21 24 27 30

4 8 12 16 20 24 28 32 36 40

5 10 15 20 25 30 35 40 45 50

6 12 18 24 30 36 42 48 54 60

7 14 21 28 35 42 49 56 63 70

8 16 24 32 40 48 56 64 72 80

9 18 27 36 45 54 63 72 81 90

10 20 30 40 50 60 70 80 90 100


Related Solutions

Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this...
(MATLAB) Write a script that would create a 3x5 matrix of random integers and write this new matrix to a file called “Assignment3_Question5.dat”.
create a function in matlab that sums two m x n matrices using nested loops, then...
create a function in matlab that sums two m x n matrices using nested loops, then returns result into a new matrix. Use nesed for loops to add matrices piece by piece. Basically means, dont program simply A+B Function should perform error check to make sure both matrices have same number of rows/ columns.
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval...
a MATLAB script that: • Prompts the user for - a lower-bound for the plot interval and stores it in a variable named Lbound - an upper-bound for the plot interval and stores it in a variable named Ubound, and - the number of points at which a function is to be evaluated to generate a plot of the function over the specified range and stores it in a variable named npoints. • Generates a plot of f(x) = x3...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1...
Write script in Matlab to solve 1. Y=Ax where X is of dimension n by 1 and A is of dimension m by n. 2. C= A*B where A is of dimension m by p and B is dimension of p by n. So write matlab script to obtain Y and C in above problems.
Write a bash script that... create new user ./finalProject user if a new user is to...
Write a bash script that... create new user ./finalProject user if a new user is to be created ask for the new users information and use it when creating the new user add a new printer ./finalProject printer ask anything you need in order to create the new printer (I.e. name) permissions ./finalProject permissions ask what document and permissions the user wants restarting the computer ./finalProject restart
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three...
Using MATLAB or Octave, Write a script that prompts the user for the coordinates of three points A, B, and C, namely (xA, yA), (xB, yB), (xC, yC), forming a triangle, storing each in a variable (for a total of 6 variables). The script should then calculate the centroid G = (xG, yG) using xG = xA+xB+xC 3 and yG = yA+yB+yC 3 , storing each in a variable. Finally, the script should print all four points. Sample output: Enter...
In MATLAB, the script should use both for and while loops. Game Mode: Randomly generates 10...
In MATLAB, the script should use both for and while loops. Game Mode: Randomly generates 10 unique (e.g. non-repeating) multiplication problems that involve multiplying the integer selected in the previous step by an integer value between 2 and 12, inclusive, after which the following report should be displayed in the Command Window. You correctly answered __ out of __ problems (__%) involving __s. The number of correctly answered problems appears in the first blank, the total number of problems appears...
Write a function such that given a number N, display the N*N multiplication matrix from 1...
Write a function such that given a number N, display the N*N multiplication matrix from 1 to N. Then, write a C++ program such that, it prints the multiplication matrices of numbers 1,4,7, and 10 using a loop concept. Check the sample output below, to see how the program should work. Make sure to have your output exactly the same as the below output.
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops,...
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops, if loops, while loops, arrays and conditional execution, as well as creating an image of the game board. The list below must be considered in the code. - Selecting a word from a dictionary (a text file) - Reading a single letter from the user - Building a character array showing the letters matched so far - Keeping count of the number of guessed...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT