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 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...
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.
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...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside...
Write a program in Java, that creates a Jframe with a menu containing only file. Inside file there should be items: Open, Save, and Save As. Selecting open prompts the user to input a file name to a txt document containing employee information and displays a Jtable with the information, which can be edited. With column headers {"First Name" , "Last Name" , "Occupation" , "Office #"} Example: Gary Osbourn Teacher 113 Michelle Ramirez Teacher 101 Ava Gomez Principal 120...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user...
Write a program that creates a file called "data.dat" in the current directory. Prompt the user for five numbers, and write them, one at a time, on both the screen and into the file. Close the file, then open it again for reading only, and display the contents on the screen. Handle error conditions that may occur. Please Need this to be done in PERL. Thanks
write a script file that calculated the first n perfect numbers. use the WHILE structure the...
write a script file that calculated the first n perfect numbers. use the WHILE structure the perfect number is a positive integer that is equal to the sum of its multiples for example 6 is a perfect number since it’s multiplied are 1, 2 and 3. 1+2+3=6 the result must be stored in a vector where all calculated perfect numbers appear. you must use the rem command matlab
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT