Function for telling if a function is unique and how many solutions it has.

Hello everyone, I'm a student who's being taught linear algebra, but being assigned matlab homework without any real explanation. I've come across this question and I need assistance with it:
Write an M-file function, that tells whether a system of linear equations has no solution, unique solution, or infinitely many solutions. The code should be such that you enter the coefficient matrix A and the corresponding column vector b. If the number of rows of A is different from the number of entries in b, the output should be an error message and execution stops. Otherwise, the output is a message indicating whether the system has no solution, unique solution, or infinitely many solutions. In this last case, it also tells the number of free variables of the system. In the case of unique solution, the code should also give the solution.
They gave me some p code to 'check what my code should do' as well but I honestly don't know how to use p-code and my version of MATLAB doesn't recognize it.

 Accepted Answer

".p" files are purposefully obfuscated, so you cannot copy the code, suggesting your instructor does not want you to use someone else's solution (which probably includes MATLAB Answers). You are meant to use lab4task3 as the "correct" answer that your function should match for the various examples.
If you are looking for advice on a good place to start, I would recommend thinking/reading about what the sizes of A and b (both rows and columns) tell you about whether the system is solvable, underdetermined or overdetermined. That will help you setup switches to alter the function's results to the correct response.

5 Comments

I'd agree with you on the p-code thing if he didn't tell us to google solutions. The guy just wanted to teach normal linear algebra but the school stuck him with computational linear algebra, so in class he teaches us normal, but assigns homework taken off of a supplied course track that's the code. But thank you on where to start.
In my opinion, there's a difference between looking for techniques online, and asking others to solve a specific problem. I'm not accusing you of that, just clarifying why I chose to respond the way I did. Others may feel differently.
If you have questions on how to implement a specific scheme or logic in MATLAB, I'm more than happy to help.
Yeah I getcha, I'm just frustrated at the class because I'm being thrown blind into the deep end. I knew how to create graphs going in, and haven't learned much of anything from the class itself because it focusses on the actual math as opposed to how to do code.
Perhaps you can use Cleve's Numerical Computing in MATLAB textbook as a supplement to the material your professor uses to teach. You can read and download the chapters and the supplemental software from here.
The prof is just saying that given a particular A and b matrix, that your own code should produce exactly the same output as lab4task3() produces for those inputs. You do not need to care how the .p is implemented. You should, though, be trying some possible inputs and taking careful note of the format of the outputs or error messages, so that you can produce exactly the same result.
For example if lab4task3(A,b) reports
Wut? Yur b und ur A r incommenserate, know u not?
then you should output exactly the same error message under the circumstances.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!