error : minus matrix dimention

2 ビュー (過去 30 日間)
Hamid
Hamid 2014 年 11 月 4 日
コメント済み: Hamid 2014 年 11 月 5 日
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;

回答 (2 件)

Roger Stafford
Roger Stafford 2014 年 11 月 5 日
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 件のコメント
Hamid
Hamid 2014 年 11 月 5 日
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.

サインインしてコメントする。


Adam
Adam 2014 年 11 月 4 日
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 件のコメント
Adam
Adam 2014 年 11 月 4 日
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 2014 年 11 月 4 日
yes it is just an error, the whole project is right

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by