Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You will write in MATLAB that multiplies a matrix by a vector Create a program i

ID: 3732352 • Letter: Y

Question

You will write in MATLAB that multiplies a matrix by a vector Create a program in MATLAB that prompts the user to enter two file names, open into dynamically allocated arrays based on the size of the data The first file will contain a matrix of arbitrary size. The format of the file will consist of two lines with a single integer on each line. These two values will represent the number of rows and columns respectively. The remainder of the file will consist of a comma separated array of floating point values. This will store the matrix. The second file will be similar to the first, but will contairn a single integer on the first line representing the number of rows in the file. Each subsequent line will contain a single floating point number. This file will store the vector If completed correctly, the program will successfully read and parse the input as well as produce the matrix-vector product. s the files, and reads the data

Explanation / Answer

Here you go

function result = Test(file1, file2)
fileID = fopen(file1,'r');
size = fscanf(fileID,'%d ', [1,2]);

A = rand(size);
for i = 1:size(1)
    for j = 1:size(2)
        x = fscanf(fileID, '%f', [1 1]);
        A(i, j) = x;
    end
end
fclose(fileID);

fileID = fopen(file2,'r');
size = fscanf(fileID,'%d ', [1,1]);

B = rand(size, 1);
for i = 1:size
    x = fscanf(fileID, '%f', [1 1]);
    A(i, 1) = x;
end
fclose(fileID);

result = A * B;

end

To change the function name just change the word in bold and underlined

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote