error : minus matrix dimention
2 views (last 30 days)
Show older comments
Hi, I have a m file that has some function, one of them is solveq and it leads to be an error.
I have attached a related mat file.
please help me out, thanks.
function [d,Q]=solveq(K,f,bc)
[nd,nd]=size(K);
fdof=[1:nd]';
%
d=zeros(size(fdof));
Q=zeros(size(fdof));
%
pdof=bc(:,1);
dp=bc(:,2);
fdof(pdof)=[];
%
s=K(fdof,fdof)\(f(fdof)-K(fdof,pdof)*dp);
%
d(pdof)=dp;
d(fdof)=s;
end
Q=K*d-f;
0 Comments
Answers (2)
Roger Stafford
on 5 Nov 2014
Hamid, your 'solveq' function is clearly intended only for an 'f' input argument consisting of a column vector, not the 3-by-n size you mentioned. The function would have to be modified to handle other than a column vector for 'f'.
It looks as if the requirements for the input arguments of 'solveq' are:
1) K should be some n-by-n square matrix
2) f should be an n-by-1 vector
3) bc should have two columns and the first column should consist of some subset of the integers from 1 to n. Consequently there should be fewer than n rows in bc.
Note that if 3) is violated, you will get an error message at the line
fdof(pdof)=[];
If K has fewer columns than rows, you will get an error message at
s=K(fdof,fdof)\(f(fdof)-K(fdof,pdof)*dp);
If f has more than one column, its columns other than the first will be ignored.
By the way, your 'end' in 'solveq' is placed one line too early and would cause 'Q' to be output as all zeros.
Adam
on 4 Nov 2014
It's very hard to work out when you don't give any information about the error, but in your attached .mat file 'pdof' has size 6 whereas 'fdof' has size 3 so I imagine the line:
s=K(fdof,fdof)\(f(fdof)-K(fdof,pdof)*dp);
may well be failing due to the domensionality mismatch.
I have no idea what the code is doing, but should the first K(fdof,fdof) maybe be K(fdof,pdof) instead?
3 Comments
Adam
on 4 Nov 2014
I'm afraid I'll have to leave that to someone else, I don't have time to look over a whole project. The title of the thread suggested the problem was just an error in matrix dimensions that you couldn't find.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!