CAT arguments dimensions not consistent.

4 views (last 30 days)
HINA
HINA on 17 May 2021
Commented: HINA on 17 May 2021
Hello,
I am getting the following messages while running the program for multiple values of 'l', (e.g: the program works well by assigning single value to l, like l=5 or l=10, l=15, l=20 etc, but doesnot work for l=5:5:20 or for l=linspace(5,20)).
error: CAT arguments dimensions not consistent.
clear all
syms logP s
P = exp(logP);
N=-P;
% l=10 % program works for individual values of l
l= 10:5:50; % problem encounter unsing a l as a vector
% l=linspace(10,50);
b=0.2;
E=200;n=2;
h0=3; h1=h0;
I0=b.*h0.^3./12; I1=b.*h1.^3./12;
L0=sqrt(P./(E.*I0-P.*n));
L1=sqrt(P./(E.*I1-P.*n));
x=(E.*I1+n.*N)./(E.*I0+n.*N);
a11=sin(L0*s);a12=s;a13=0;a14=0;
a21=0;a22=0;a23=-sin(L1*(l-s));a24=(s-l).*cos(L1*l);
a31=-L0.*cos(L0*s).*cos(L1*l);a32=-cos(L1*l);a33=L1.*cos(L1*(l-s));a34=cos(L1*l);
a41=L0.^2.*sin(L0*s).*cos(L1*l);a42=0;a43=x.*L1.^2.*sin(L1*(l-s));a44=0;
A=[a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44];
deltaA=det(A);
s=1;
delta=subs(deltaA,s);
F=matlabFunction(delta);
logP1=[];
for j = log(0.01:10)
logPP = fzero(F, j);
logP1 = vertcat(logP1, logPP);
end
logP1 = [logP1; logPP];
P1 = exp(logP1);
P_cr = min(P1(P1 > 0))
  2 Comments
Rik
Rik on 17 May 2021
How would you do this with pen and paper if you have a vector l? Should A be a 3D matrix? Should it be wider? Taller?
It looks like you need a loop. It doesn't look to me like your computations are properly defined for a non-scalar l.
NB: you should avoid lowercase l as a variable name, because it looks a lot like a 1 in many mono-spaced fonts.
HINA
HINA on 17 May 2021
Thank you Rik for your valuable suggestions. I have already tried with the for loop as well, and that's also not working for me. I am sharing the code and the error
clear all
syms logP s
P = exp(logP);
N=-P;
for l=linspace(10,50,5);
b=02;
E=200;n=2;
h0=3; h1=h0;
I0=b*h0^3/12; I1=b*h1^3/12;
L0=sqrt(P/(E*I0-P*n));
L1=sqrt(P/(E*I1-P*n));
x=(E*I1+n*N)/(E*I0+n*N);
a11=sin(L0*s);a12=s;a13=0;a14=0;
a21=0;a22=0;a23=-sin(L1*(l-s));a24=(s-l)*cos(L1*l);
a31=-L0*cos(L0*s)*cos(L1*l);a32=-cos(L1*l);a33=L1*cos(L1*(l-s));a34=cos(L1*l);
a41=L0^2*sin(L0*s)*cos(L1*l);a42=0;a43=x*L1^2*sin(L1*(l-s));a44=0;
A=[a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44]
deltaA=det(A);
s=1;
delta=subs(deltaA,s);
F=matlabFunction(delta);
logP1=[];
for j = log(001:10)
logPP = fzero(F, j);
logP1 = vertcat(logP1, logPP);
end
P1 = exp(logP1);
P_cr = min(P1(P1 > 0))
end
it returns the following error
Too many input arguments.

Sign in to comment.

Accepted Answer

Rik
Rik on 17 May 2021
There are several issues with your code. After applying the correct indentation, here are my edits.
The source of your error is probably the fact that you overwrite s with 1.
l_list=linspace(10,50,5);
P_cr=zeros(size(l_list));
for n=1:numel(l_list)
P_cr(n)=calculate_P_cr(l_list(n));
end
disp(P_cr)
142.7270 43.8971 20.1769 11.4483 7.3452
function P_cr=calculate_P_cr(l)
%Write documentation for this function here.
%describe inputs and expected output
You should also write comments for every idea. An idea can span a single line or a few lines. Make sure other people reading your code can understand what you're doing.
%clear all
clear all is mostly equivalent to restarting Matlab every time you run your code. It will do what you need, but at an unnecessary performance cost. clear or clearvars is enough in scripts. Outside of debugging you should use functions to keep your workspace clean.
%initialize symbolic variables
syms logP s
P = exp(logP);
N=-P;
%initialize constants
b=02;
E=200;
n=2;
h0=3;
h1=h0;
I0=b*h0^3/12;
I1=b*h1^3/12;
L0=sqrt(P/(E*I0-P*n));
L1=sqrt(P/(E*I1-P*n));
x=(E*I1+n*N)/(E*I0+n*N);
A little bit of whitespace might improve how readable your code is
%create the A matrix
a11=sin(L0*s); a12=s; a13=0; a14=0;
a21=0; a22=0; a23=-sin(L1*(l-s)); a24=(s-l)*cos(L1*l);
a31=-L0*cos(L0*s)*cos(L1*l); a32=-cos(L1*l);a33=L1*cos(L1*(l-s)); a34=cos(L1*l);
a41=L0^2*sin(L0*s)*cos(L1*l);a42=0; a43=x*L1^2*sin(L1*(l-s));a44=0;
A=[a11 a12 a13 a14;a21 a22 a23 a24;a31 a32 a33 a34;a41 a42 a43 a44];
deltaA=det(A);
s=1;%this overwrites the symbolic variable with an explicit value
delta=subs(deltaA,s);
F=matlabFunction(delta);
exp_list = log(001:10);
Are you sure you don't mean log10(0.01):log10(10)?
logP1=zeros(size(exp_list));
for n=1:numel(exp_list)
logPP = fzero(F, exp_list(n));
logP1(n) = logPP;
You had a dynamically expanding array here. You shouldn't do that if you can determine the size beforehand.
end
P1 = exp(logP1);
P_cr = min(P1(P1 > 0));
Because exp(x)==0 will only be true for x=-inf, you could consider skipping the indexing.
end
  1 Comment
HINA
HINA on 17 May 2021
A big thanks for such a detailed description. That’s a great help.

Sign in to comment.

More Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!