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
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Financial Toolbox 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by