Writing a function that returns a column vector

I need to create a function that accepts three parameters (a,b,n) and returns the solution to an nxn system as a column vector. I have a given AX=B system, with A being an identity matrix that has some random units filled with a's and b's that is nxn and B being a column vector that is n units long.
I know how to create a basic function, but I do not know how to create all of the matrices that are dependent on the user's choice of n. I also do not know how to output a column vector.
Much thanks in advance!

2 comentarios

Image Analyst
Image Analyst el 7 de Sept. de 2012
"A being an identity matrix that has some random units filled with a's and b's" Huh????? The identity matrix, generated by eye(n), has 1s along the diagonal and zeros elsewhere, not random numbers all over the place. Can you give a specific numerical example of your type of identity matrix?
Azzi Abdelmalek
Azzi Abdelmalek el 7 de Sept. de 2012
it's not clear for me

Iniciar sesión para comentar.

Respuestas (1)

Image Analyst
Image Analyst el 7 de Sept. de 2012
You say you know how to create functions, but why didn't
function columnVector = MatMult(a, b)
columnVector = a * b;
work for you? By the way, you don't need to pass in n - you can determine it from the matrices themselves. You don't even need it unless you want to do some input validation in advance of multiplying - which is a very good idea. Alternatively, put in a try catch and alert the user of mismatching sizes in the catch block once it fails.

Categorías

Más información sobre Creating and Concatenating Matrices en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 7 de Sept. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by