Question

Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors)

Matlab question

Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) A system of linear algebraic equat

Your Function MATLAB Documentation C Reset 1 function [linearsystem] atrixInterpreter(A, b) Enter the commands for your funct

Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) A system of linear algebraic equations can be writen in matrx notation by applying the definizion of matrix multiplication. For example, the linear system Can be writen as or where and x = 2 matrix input ror the variable A and a × T e function command dennes the output variable linearSystem Code has alread been provided to define a runcion named natrix Interpreter that accepts a matri input forthe vart ble b Add commands to use the values in the input variables A and b to build a single column cell array of character vectors where the first cell contains a character vector defining the first equation in the system and the second cell contains a character vector defining the second equaton n e s stem ss n this stinn o t e output a able nearSys en spaces in he character vectors de ining e e Lations For example w n the above system ofe u ns example țhe unct Inputs would be o no ї se a defined as A - [3 -2; 2 41 b - [S -21 The cell array output of the function would be Your code should work for any integer values of the inputs A and b including possible negative values in order to pass all the test cases.
Your Function MATLAB Documentation C Reset 1 function [linearsystem] atrixInterpreter(A, b) Enter the commands for your function here. Be sure to assign values Jİ%to the output variable linearsysten defined in the function command on line 1 Code to call your function С Reset A -13 -2; 2 4: 2b[5-2] 3linearSysten matrixInterpreter(A, b) Run Function Output Run Pretest Submit Is output variable linearSystem correct for example inputs given in the problem statement? (Pretest) Is output correct for randomly generated values in the input variables?
0 0
Add a comment Improve this question Transcribed image text
Answer #1

% function to build a single column cell array of character vectors where
% the first cell contains a cell vector defining the first equation in the
% system and second cell contains a cell vector defining the first equation in the
% system
function [linearSystem] = matrixInterpreter(A,b)
linearSystem = {};
% loop over the rows of A and assign equations to linearSystem
for i =1:size(A,1)
eq = strcat(num2str(A(i,1)),'x');
if(A(i,2) < 0) % if A(i,2) is negative don't insert + sign
eq = strcat(eq,num2str(A(i,2)),'y');
else
eq = strcat(eq ,'+',num2str(A(i,2)),'y');
end
eq = strcat(eq, '=', num2str(b(i)));
linearSystem{i,1} = eq;
end
end

%end of function

Output:

>>A [3,-22,41 >5-21: >> linearSystem matrixInterpreter (A, b) linearSystem 2x1 cell array f3x-2y-5 (2x+4y-2)

Add a comment
Know the answer?
Add Answer to:
Question:Matrix Notation Interpreter (matrix elements to cell array of formatted character vectors) Matlab question Matrix Notation Interpreter (matrix elements to cell array of formatted character...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Assignment 1) Your function will only write the Nth character of the array, supplied as a...

    Assignment 1) Your function will only write the Nth character of the array, supplied as a parameter by the caller. This is an example prototype (although you may want to change the return value type, based on the second twist, below). void writeArrayNthBackward(const char [], int, int, int); The first three arguments serve the same purpose as in the iterative example. The fourth argument (an int) supplies the N for the Nth character to print in the array. If n...

  • IN JAVA please Given a sorted array and a target value, return the index if the...

    IN JAVA please Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order. Your code will be tested for runtime. Code which does not output a result in logarithmic time (making roughly log(2) N comparisons) will fail the tests. A sample main function is provided so that you may test your code on sample inputs. For testing purposes, the...

  • need answer for matlab programming for engineers and scientists x.3 1.3e+02 2 Ore ersion un SCII Sta Exercise 5.3 1. Make a cell array called c that contains the following eleven strings the c...

    need answer for matlab programming for engineers and scientists x.3 1.3e+02 2 Ore ersion un SCII Sta Exercise 5.3 1. Make a cell array called c that contains the following eleven strings the cow l num- 7.2 CHAPTER 5: Data Types 138 SLS the Write code that accesses the cell at index 7 i 2. use the correct type of brackets. Use the function class to confirm that a cell is returned. I c 3. write code that accesses the...

  • Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture...

    Nay programming languge is fine (MatLab, Octave, etc.) This is the whole document this last picture i sent is the first page 5. Write and save a function Sphere Area that accepts Radius as input argument, and returns SurfaceArea (4 tt r) as output argument. Paste the function code below. Paste code here 6. Validate your Sphere Area function from the command line, checking the results against hand calculations. Paste the command line code and results below. 7. Design an...

  • 29. (20 points) Write the complete C++ program that implements the following program, as if you...

    29. (20 points) Write the complete C++ program that implements the following program, as if you were turning this in for homework. Your program should have a commented header (your name, etc), comments within the program and a well-built display for the output. Don't forget the pre-processor commands Define an array called nums with a maximum of 20 integers, and fill the array with numbers, recei the keyboard (prompt for the numbers.) In this program, exactly 20 integers will be...

  • matlab( answer the question in matlab) show the full answer with comment please. W a rnction...

    matlab( answer the question in matlab) show the full answer with comment please. W a rnction to find the largest product of adjacent number pairs in a matrix, where pair combinations can be selected the horsonal accent or vertically adjacent (but not diagonally adjacent) of numbers in a matrix are accent if they are in the same row or column and located next to each other when the 2D matrix is displayed The largest product of a pair of adjacent...

  • 6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you...

    6.15 Program 6: Using Arrays to Count Letters in Text 1. Introduction In this program, you will practice working with arrays. Your program will read lines of text from the keyboard and use an array to track the number of times each letter occurs in the input text. You will use the contents of this array to generate a histogram (bar graph) indicating the relative frequencies of each letter entered. Test cases are available in this document. Remember, in addition...

  • C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible;...

    C++ please Possible algorithms – (1) use and modify the algorithm from program 2 if possible; (2) use unique value array; (3) use flag array (flags used to avoid counting a number more than 1 time); (4) compute frequency distribution (use unique and count arrays); (5) use count array to store the frequency of a number. No global variable are permitted in this assignment. Do not change the code provided only write the missing code. Write the missing C++ statements...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT