how do i fix "inner matrix dimensions must agree" in this formula?

조회 수: 1 (최근 30일)
Mikel lynch
Mikel lynch 2014년 11월 19일
댓글: C.J. Harris 2014년 11월 20일
I am trying to input a number of variables into a formula which are listed in the code below (r=radial coordinate). I have seen other answers covering this same error but still cannot solve it. i have tried using ./ .* etc. in different places but to no avail. Error is: Error using * Inner matrix dimensions must agree.
Error in project2 (line 19) w=(P*rd^4)./(64*K*(1+v))*(2*(3+v).*(1-(r./rd).^2)-(1+v).*(1-(r./rd).^4))
Can anyone advise as to where my mistake is? Thanks.
Code is:
if true
% code
end
function [ w,wmax ] = project2( E,K )
%project2 Function to determine deflection (w) at a certain pressure until
%deflection exceeds wmax.
%
v=0.3; %poissons ratio for all materials
t=0.005; %plate thickness, measured in meters
rd=0.15; %plate radius, measured in meters
for P=0:5000:50000;
wmax=P*(rd^4)*(5+v)/64*K*(1+v);
if wmax<=0.0025;
rad=(0:0.01:0.15);
theta=(0:24:360);
[thm, rm]=meshgrid(theta,rad);
[X,Y]=pol2cart(thm,rm);
r=[X,Y];
w=(P*rd^4)./(64*K*(1+v))*(2*(3+v).*(1-(r./rd).^2)-(1+v).*(1-(r./rd).^4))
else pause
end
end
end
  댓글 수: 3
Mikel lynch
Mikel lynch 2014년 11월 19일
K is [8.032459778783307e+02,0.015711412770235] in this case, it is defined in the original script. just realised now E was only needed for the formula for K. would the fact that there are two parts to K be causing the issue here? i also ran it for K= a single integer and resulted with zeroes.
Adam
Adam 2014년 11월 19일
Well, yes, you can do plenty of maths with scalars, but as soon as you start passing in matrices or greater dimensionality you have to be very precise with your formula to avoid getting dimension mis-matches for multiplying and dividing.

댓글을 달려면 로그인하십시오.

채택된 답변

C.J. Harris
C.J. Harris 2014년 11월 19일
Some of your defined vectors are of a fixes size, for example:
rad=(0:0.01:0.15);
theta=(0:24:360);
Therefore your function is only going to work for scalar inputs (not vectors or matrices) unless you rework the line:
w=(P*rd^4)./(64*K*(1+v))*(2*(3+v).*(1-(r./rd).^2)-(1+v).*(1-(r./rd).^4))
Also your if statement will probably not work as you intend for non scalar inputs as wmax will be the same size as K:
if wmax<=0.0025
  댓글 수: 2
Mikel lynch
Mikel lynch 2014년 11월 20일
how do i go about reworking the line so that it will work? i have changed the if statement to a while wmax<=0.0025, will this work instead? Thank you, i really appreciate the guidance!
C.J. Harris
C.J. Harris 2014년 11월 20일
You's have to think about what a matrix input actually meant. Possibly loop through all the values. It's not as simple as just 'fixing it'.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by