error : minus matrix dimention

2 views (last 30 days)
Hamid
Hamid on 4 Nov 2014
Commented: Hamid on 5 Nov 2014
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;

Answers (2)

Roger Stafford
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.
  1 Comment
Hamid
Hamid on 5 Nov 2014
Thank you Roger but these can not solve my problem.
I attached my whole project and I have to to change f matrix from 3-by-1 to 3-by-n.
GAmadule function is the main and it leads to an error in solveq function when I want to change f matrix.
for example you can input :
sq=235
nb=2....x=0 y=0 z=0 x=5000 y=0 z=0
nl=1....x=2500 y=2500 z=10000...fx=0 fy=0 fz=-1000
nn=3
please help, you are the best dear Roger.

Sign in to comment.


Adam
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
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.
Hamid
Hamid on 4 Nov 2014
yes it is just an error, the whole project is right

Sign in to comment.

Categories

Find more on Mathematics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!