Question

In: Computer Science

Write a program in a script file that creates m × n matrix with elements that...

  1. Write a program in a script file that creates m × n matrix with elements that have the following values. The value of each element in the last row is the number of the column. The value of each element in the last column is the number of row +1. For the rest of the elements, each has a value equal to the sum of the element below it and the element to the right.

Solutions

Expert Solution

Code:

Output:

Flow Chart:

Copyable Code:

n = input('Enter n value: ');

m = input('Enter m value: ');

%Fill zeros to array

A = zeros(n,m);

%loop to calculate the array values and fill them

for l = 1:n

    for k = 1:m

        if l == 1

            %First row

            A(l,k) = k;

        elseif k == 1

            %First column

            A(l,k) =l;

        else

            %Elements left

            A(l,k) = A(l-1,k) + A(l, k-1);

        end

    end

end

%Array

disp(A)

Related Solutions

Write a java program: Write a program that creates a text file. Write to the file...
Write a java program: Write a program that creates a text file. Write to the file three lines each line having a person's name. In the same program Append to the file one line of  'Kean University'.  In the same program then Read the file and print the four lines without lines between.
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...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100...
Write a program that creates an output file named rand_nums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file. Write a program that opens rand_nums.txt for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write...
Write a C++ program that creates a file called Readings.txt. Inside the file, your program must...
Write a C++ program that creates a file called Readings.txt. Inside the file, your program must create a list. The list is composed of integer double pairs. There is one pair per line. The integers are in sequence (0, 1, 2, 3, ...) beginning with zero and ending with some random value between 512 and 1024. The doubles should be random values between 50.000 and 90.000. The doubles only have 3 decimal places. The file should look like this (of...
Suppose C is a m × n matrix and A is a n × m matrix....
Suppose C is a m × n matrix and A is a n × m matrix. Assume CA = Im (Im is the m × m identity matrix). Consider the n × m system Ax = b. 1. Show that if this system is consistent then the solution is unique. 2. If C = [0 ?5 1 3 0 ?1] and A = [2 ?3   1 ?2    6 10] ,, find x (if it exists) when (a) b =[1...
Write a c program that creates a struct to be able to read a .img file...
Write a c program that creates a struct to be able to read a .img file and a .pat file.
a – DSB. Write the code for an m-file (script) to generate a DSB signal. The...
a – DSB. Write the code for an m-file (script) to generate a DSB signal. The modulating (message) signal is a single tone signal with frequency 1kHz and the carrier frequency is 30kHz. Time Vector: 3001 points over range from 0 to 3ms (3 cycles of the modulating signal). Plot your original message signal both in time and its spectrum. (Note: the Matlab examples 6.1 and 6.2 will help, but use the cosine functions for your signals instead of sine...
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Specification This script reads in class data from a file and creates a dictionary. It then...
Specification This script reads in class data from a file and creates a dictionary. It then prints the data from the dictionary. The script has the following functions class_tuple_create print_classes class_tuple_create This function has the following header def class_tuple_create(filename): The function reads in a file with four fields of data about a class. The fields are Course ID Room number Instructor Start time The function must print an error message if the file cannot be opened for any reason. The...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT