error : minus matrix dimention

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;

Respuestas (2)

Roger Stafford
Roger Stafford el 5 de Nov. de 2014

1 voto

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 comentario

Hamid
Hamid el 5 de Nov. de 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.

Iniciar sesión para comentar.

Adam
Adam el 4 de Nov. de 2014

0 votos

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 comentarios

Hamid
Hamid el 4 de Nov. de 2014
I attached my whole project and I want 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
Adam
Adam el 4 de Nov. de 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 el 4 de Nov. de 2014
yes it is just an error, the whole project is right

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Preguntada:

el 4 de Nov. de 2014

Comentada:

el 5 de Nov. de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by