Linear systems of equations are something that those in all engineering majors w
ID: 3858456 • Letter: L
Question
Linear systems of equations are something that those in all engineering majors will see in their sophomore level classes. Inherently linear algebra is all about solving systems of equations. Because you’re good at MATLAB you know that you can find the solution to a system of equations using the solve() or linsolve() functions or by simply using the backslash ‘’ operator. But you’re taking linear algebra with Dr. Quaini from the math department who wants you to demonstrate that you understand how MATLAB performs these operations, so she asks you to implement 3 user defined functions. The first function named ‘Uptri’ should take some NxN+1 sized matrix and change it to upper triangular form. The first N columns correspond to the coefficients, and the last Nx1 column should represent the solutions to the equations (in the example below the first line in your input represents the eqn 1*X1+0*X2+3*X3=4). Your code should also notify the user if they have entered a system that has more than one solution. (NOTE: linear systems can have more than one equivalent upper-triangular form, so depending on the method that you implement, you may not get the same matrices you see here.) Look up Gaussian Elimination to understand how to accomplish this.
A function for counter where it checks the matrix for being an NxN+1 matrix,
o If not correct the first three times will output a warning, and ask to re input the matrix
o if not correct after three tries it will error out of the program
• Display Function
o Use loops and conditionals to display the unique solution of the Upper Triangle form
o No implicit loops
• Once Uptri has been found check if there is no solution, infinite solutions, unique solutions within Uptri
o It must error in the Uptri Function for no solution, infinite solution
o Unique solution should say unique solution
Three user defined functions (Counter, Uptri, and Display)[you must capitalize the function names]
Can anyone please hel? This code needs to be done on MATLAB.
Explanation / Answer
Example: 1).Suppose: N= 4
In MATLAB, you create a matrix by entering elements in each row as comma or space delimited numbers and using semicolons to mark the end of each row.
MATLAB will execute the above statement and return the following result
Example: 2).Suppose: N= 3
// y and stores the result in matrix z
#include <iostream>
using namespace std;
#define m 3
#define c 2
#define n 4
int main()
{
int i, j, k;
// first matrix...
int x[m][c] = {{1,2},{3,4},{5,6}};
// second matrix...
int y[c][n] = {{7,8,9,10},{11,12,13,14}};
// for storing the matrix product result...
int z[m][n];
for(i=0; i<m; i++)
for(j=0; j<n; j++)
{
z[i][j] = 0;
for(k=0; k<c; k++)
// same as z[i][j] = z[i][j] + x[i][k] * y[k][j];
z[i][j] += x[i][k] * y[k][j];
}
cout<<" Multiply matrix x and matrix y,";
cout<<" Then store the result in matrix z.";
cout<<" Matrix x is 3x2, and matrix y is 2x4,";
cout<<" so, the result, z should be matrix 3x4 ";
cout<<" The matrix product is: ";
for (i=0; i<m; i++)
{
cout<<" ";
for(j=0; j<n; j++)
// display the result...
cout<<" "<<z[i][j];
}
cout<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.