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 个评论
Image Analyst
2012-9-7
"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
2012-9-7
it's not clear for me
回答(1 个)
Image Analyst
2012-9-7
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.
类别
在 帮助中心 和 File Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!