이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
조회 수: 3 (최근 30일)
이전 댓글 표시
I have been getting the error "Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN."
In the '.xlsx' sheet i have bunch of numbers that have been taken from a cfd software. Can anyone help me with this one why I am getting this error? (I think the error might be due to the excel file only but am not sure since the file contain just a list of numbers)
Here is the complete code:
Main code:
clear all
clc
global K M C u;
Ne=6;
l=1; %length
t=0.02; %thickness
b=0.02; %width
modulus=2e11; %(E)
area=b*t;
imoment=(b*((t)^3))/12;
Le=l/Ne; %length of element
Rho=7850; %density
%Element stiffness matrix
K1=(modulus*imoment/(Le^3))*[12,6*Le,-12,6*Le; ...
6*Le,4*Le*Le,-6*Le,2*Le*Le; ...
-12,-6*Le,12,-6*Le; ...
6*Le,2*Le*Le,-6*Le,4*Le*Le];
Kglobal=zeros(2*(Ne+1),2*(Ne+1));
M1=[156 22*Le 54 -13*Le;...
22*Le 4*Le*Le 13*Le -3*Le*Le;...
54 13*Le 156 -22*Le;...
-13*Le -3*Le*Le -22*Le 4*Le*Le]*(Rho*Le*b*t)/420;
Mglobal=zeros(2*(Ne+1),2*(Ne+1));
for ii=1:Ne
Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+K1;
Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+M1;
end
K=Kglobal;
K(1:2,:)=[];
K(:,1:2)=[];
M=Mglobal;
M(1:2,:)=[];
M(:,1:2)=[];
C=0.05*Kglobal;
C(1:2,:)=[];
C(:,1:2)=[];
K
M
C
u=(2*Ne)+1;
dt=0.001;
T=300;
%Displacement initials
y0=zeros(2*(2*(Ne+1))-4,1);
y0(end-1,1)=0.5;
%ODE function
t_array = xlsread('l&d.xlsx','Q1:Q300'); % This is t array from xls file
f_array = xlsread('l&d.xlsx','O1:O300'); % This is F array from xls file
[tsol ysol]=ode15s(@(t, y) beam_function(t, y, t_array, f_array),[1:dt:T],y0);
plot(tsol,ysol(:,Ne))
Function code:
function [dy]=beam_function(t,y, t_array, f_array)
F = interp1(t_array,f_array,t);
dy=[y(1:u-1);
inv(M)*(F-K*y(u:end)-C*y(1:u-1))]
채택된 답변
Walter Roberson
2021년 8월 21일
Inside your function the following variables are not defined: C, K, M, u
Global variables are only accessible inside functions that declare them as global (or inside nested functions of a function that declared them global.)
Avoid using global.
Note: there is no point in taking inv(M) inside the function, as you do not change M inside the function. Either use M\(F-K*y(u:end)-C*y(1:u-1)) or else calculate inv(M) outside and pass in the inverse.
Note: using interp1() with no interpolation method specified results in linear interpolation. However, linear interpolation of a variable results in the derivative of F being discontinuous, which is something that will cause problems with the ode*() routines, as the ode*() routines rely upon the second derivative of all statements to be continuous. If you must interpolate, then use 'spline' method.
댓글 수: 10
Bhanu Pratap Akherya
2021년 8월 21일
Now, I used the spline method for interpolation but the error shown now is "Not enough input arguments."
I don't know what that means can you explain that please?
Walter Roberson
2021년 8월 21일
Most likely you coded
F = interp1(t_array,f_array,t,spline);
when you neeed to have coded
F = interp1(t_array,f_array,t,'spline');
Walter Roberson
2021년 8월 21일
format long g
Ne=6;
l=1; %length
t=0.02; %thickness
b=0.02; %width
modulus=2e11; %(E)
area=b*t;
imoment=(b*((t)^3))/12;
Le=l/Ne; %length of element
Rho=7850; %density
%Element stiffness matrix
K1=(modulus*imoment/(Le^3))*[12,6*Le,-12,6*Le; ...
6*Le,4*Le*Le,-6*Le,2*Le*Le; ...
-12,-6*Le,12,-6*Le; ...
6*Le,2*Le*Le,-6*Le,4*Le*Le];
Kglobal=zeros(2*(Ne+1),2*(Ne+1));
M1=[156 22*Le 54 -13*Le;...
22*Le 4*Le*Le 13*Le -3*Le*Le;...
54 13*Le 156 -22*Le;...
-13*Le -3*Le*Le -22*Le 4*Le*Le]*(Rho*Le*b*t)/420;
Mglobal=zeros(2*(Ne+1),2*(Ne+1));
for ii=1:Ne
Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+K1;
Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+M1;
end
K=Kglobal;
K(1:2,:)=[];
K(:,1:2)=[];
M=Mglobal;
M(1:2,:)=[];
M(:,1:2)=[];
C=0.05*Kglobal;
C(1:2,:)=[];
C(:,1:2)=[];
K
K = 12×12
13824000 0 -6912000 576000 0 0 0 0 0 0 0 0
0 128000 -576000 32000 0 0 0 0 0 0 0 0
-6912000 -576000 13824000 0 -6912000 576000 0 0 0 0 0 0
576000 32000 0 128000 -576000 32000 0 0 0 0 0 0
0 0 -6912000 -576000 13824000 0 -6912000 576000 0 0 0 0
0 0 576000 32000 0 128000 -576000 32000 0 0 0 0
0 0 0 0 -6912000 -576000 13824000 0 -6912000 576000 0 0
0 0 0 0 576000 32000 0 128000 -576000 32000 0 0
0 0 0 0 0 0 -6912000 -576000 13824000 0 -6912000 576000
0 0 0 0 0 0 576000 32000 0 128000 -576000 32000
rank(K)
ans =
12
M
M = 12×12
0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0 0 0 0 0
0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0 0 0 0 0
0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0 0 0
-0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0 0 0
0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0
0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0
0 0 0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0
0 0 0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0
0 0 0 0 0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545
0 0 0 0 0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979
rank(M)
ans =
12
C
C = 12×12
691200 0 -345600 28800 0 0 0 0 0 0 0 0
0 6400 -28800 1600 0 0 0 0 0 0 0 0
-345600 -28800 691200 0 -345600 28800 0 0 0 0 0 0
28800 1600 0 6400 -28800 1600 0 0 0 0 0 0
0 0 -345600 -28800 691200 0 -345600 28800 0 0 0 0
0 0 28800 1600 0 6400 -28800 1600 0 0 0 0
0 0 0 0 -345600 -28800 691200 0 -345600 28800 0 0
0 0 0 0 28800 1600 0 6400 -28800 1600 0 0
0 0 0 0 0 0 -345600 -28800 691200 0 -345600 28800
0 0 0 0 0 0 28800 1600 0 6400 -28800 1600
rank(C)
ans =
12
u=(2*Ne)+1;
dt=0.001;
T=300;
%Displacement initials
y0=zeros(2*(2*(Ne+1))-4,1);
y0(end-1,1)=0.5;
%ODE function
t_array = xlsread('l&d.xlsx','Q1:Q300'); % This is t array from xls file
Error using xlsread (line 136)
Unable to open file 'l&d.xlsx'.
File '/users/mss.system.M0BtCI/l&d.xlsx' not found.
Unable to open file 'l&d.xlsx'.
File '/users/mss.system.M0BtCI/l&d.xlsx' not found.
f_array = xlsread('l&d.xlsx','O1:O300'); % This is F array from xls file
[tsol ysol]=ode15s(@(t, y) beam_function(t, y, t_array, f_array, C, K, M, u),[1:dt:T],y0);
plot(tsol,ysol(:,Ne))
function [dy]=beam_function(t,y, t_array, f_array)
F = interp1(t_array,f_array,t,'spline');
dy=[y(1:u-1);
M\(F-K*y(u:end)-C*y(1:u-1))]
end
Bhanu Pratap Akherya
2021년 8월 21일
thanks for your help the issue was exactly as you told. But the original error is still showing up: "Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN." could it be due to the .xlsx file?
Walter Roberson
2021년 8월 22일
편집: Walter Roberson
2021년 8월 22일
I am not seeing it in R2021a.
The current code is
filename = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/718084/l&d.xlsx';
format long g
Ne=6;
l=1; %length
t=0.02; %thickness
b=0.02; %width
modulus=2e11; %(E)
area=b*t;
imoment=(b*((t)^3))/12;
Le=l/Ne; %length of element
Rho=7850; %density
%Element stiffness matrix
K1=(modulus*imoment/(Le^3))*[12,6*Le,-12,6*Le; ...
6*Le,4*Le*Le,-6*Le,2*Le*Le; ...
-12,-6*Le,12,-6*Le; ...
6*Le,2*Le*Le,-6*Le,4*Le*Le];
Kglobal=zeros(2*(Ne+1),2*(Ne+1));
M1=[156 22*Le 54 -13*Le;...
22*Le 4*Le*Le 13*Le -3*Le*Le;...
54 13*Le 156 -22*Le;...
-13*Le -3*Le*Le -22*Le 4*Le*Le]*(Rho*Le*b*t)/420;
Mglobal=zeros(2*(Ne+1),2*(Ne+1));
for ii=1:Ne
Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Kglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+K1;
Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))=Mglobal(2*ii-1:2*(ii+1),2*ii-1:2*(ii+1))+M1;
end
K=Kglobal;
K(1:2,:)=[];
K(:,1:2)=[];
M=Mglobal;
M(1:2,:)=[];
M(:,1:2)=[];
C=0.05*Kglobal;
C(1:2,:)=[];
C(:,1:2)=[];
K
K = 12×12
13824000 0 -6912000 576000 0 0 0 0 0 0 0 0
0 128000 -576000 32000 0 0 0 0 0 0 0 0
-6912000 -576000 13824000 0 -6912000 576000 0 0 0 0 0 0
576000 32000 0 128000 -576000 32000 0 0 0 0 0 0
0 0 -6912000 -576000 13824000 0 -6912000 576000 0 0 0 0
0 0 576000 32000 0 128000 -576000 32000 0 0 0 0
0 0 0 0 -6912000 -576000 13824000 0 -6912000 576000 0 0
0 0 0 0 576000 32000 0 128000 -576000 32000 0 0
0 0 0 0 0 0 -6912000 -576000 13824000 0 -6912000 576000
0 0 0 0 0 0 576000 32000 0 128000 -576000 32000
rank(K)
ans =
12
M
M = 12×12
0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0 0 0 0 0
0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0 0 0 0 0
0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0 0 0
-0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0 0 0
0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0 0 0
0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0 0 0
0 0 0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545 0 0
0 0 0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979 0 0
0 0 0 0 0 0 0.0672857142857143 0.00269973544973545 0.388761904761905 0 0.0672857142857143 -0.00269973544973545
0 0 0 0 0 0 -0.00269973544973545 -0.000103835978835979 0 0.00027689594356261 0.00269973544973545 -0.000103835978835979
rank(M)
ans =
12
C
C = 12×12
691200 0 -345600 28800 0 0 0 0 0 0 0 0
0 6400 -28800 1600 0 0 0 0 0 0 0 0
-345600 -28800 691200 0 -345600 28800 0 0 0 0 0 0
28800 1600 0 6400 -28800 1600 0 0 0 0 0 0
0 0 -345600 -28800 691200 0 -345600 28800 0 0 0 0
0 0 28800 1600 0 6400 -28800 1600 0 0 0 0
0 0 0 0 -345600 -28800 691200 0 -345600 28800 0 0
0 0 0 0 28800 1600 0 6400 -28800 1600 0 0
0 0 0 0 0 0 -345600 -28800 691200 0 -345600 28800
0 0 0 0 0 0 28800 1600 0 6400 -28800 1600
rank(C)
ans =
12
u=(2*Ne)+1;
dt=0.001;
T=300;
%Displacement initials
y0=zeros(2*(2*(Ne+1))-4,1);
y0(end-1,1)=0.5;
%ODE function
t_array = readmatrix(filename, 'range', 'Q1:Q300'); % This is t array from xls file
f_array = readmatrix(filename, 'range', 'O1:O300'); % This is F array from xls file
[tsol, ysol]=ode15s(@(t, y) beam_function(t, y, t_array, f_array, C, K, M, u),[1:dt:T],y0);
plot(tsol,ysol(:,Ne))
function [dy]=beam_function(t,y, t_array, f_array, C, K, M, u)
F = interp1(t_array,f_array,t,'spline');
dy=[y(1:u-1);
M\(F-K*y(u:end)-C*y(1:u-1))];
end
Bhanu Pratap Akherya
2021년 8월 22일
did you get the result on 2021a? can please share what were the results?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Financial Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 MathWorks 사이트 방문이 최적화되지 않았습니다.
미주
- América Latina (Español)
- Canada (English)
- United States (English)
유럽
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)