Use or Pi and raising matrix to a Power

3 次查看(过去 30 天)
Hello
I have written the below scrip to investigate beam theory calculations for set dimensions of a beam. I keep the getting the follownig error message:
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and
the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in Partial_UDL_Clarity_Version (line 26)
I1 = (pi)*r1^4/4; % [m^4] second moment of area
I am trying to add and upper and lower limit to the beam dimensions (length and radius) in order to then plot this variability as seperate lines. ideally i would then shade between these extremes with the mid point line going through the middle.
I have found this code for trying to shade between these two lines:
%This fills the area between the lower and upper bounds with one of the
%colours from the start. An example is shown below
%x'line1''line2' = [Delta'line1', fliplr(Delta'line2')];
%inBetween'line1''line2' = [F, fliplr(F)];
%'line1''line2' = fill(x'line1''line2', inBetween'line1''line2', Colour'x');
xef = [Deltae, fliplr(Deltaf)];
inBetweenef = [F, fliplr(F)];
ef = fill(xef, inBetweenef,Colour5);
Any help would be greatly appreciated.
Thanks in advance.
The Full script/Code is here:
%Created Friday 13th 2020 Robert Staruch Beam Deflection Partial UDL
%-------------------------------------------------------------------
%This code is to Calculate Deflection of a beam of Partial loading over a
%set length.
%REMEMBER in this situation H1 is the greater height, and H2 is the lower
%height.
%REMEMBER that the tip deflection value will be the difference between the
%TOTAL BEAM LENGTH, and the respective UDL heights. So for H1 that will be
%Total Length - H1, and for H2 that is Total Length - H2. In most of these
%cases we are using a 12mm beam, so it is 12-H1, 12-H2. V Important.
%The parameters are
r1 = 0.0007500: 0.0000025: 0.0007525 % [m] radius of bar
P1 = 0.0001:0.0001:0.001; % [N] load applied on the beam
l1 = 0.012: 0.00025: 0.01225 % [m] length of beam
H1 = 0.010: 0.00025: 0.01025 % Upper height of partial load
H2 = 0.00800; % Lower height of Partial Load
D1 = 0.00200; % Length of Partial load. Should be difference between H1&H2.
D2 = 0.00400; % Difference between L1 and H2.
E1 = 2.26e6; % [Pa] youngs modulas in Pa PDMS
E2 = 4.446e6; % [Pa] youngs modulas in Pa Elastic
E3 = 10.5e6; % [Pa] youngs modulas in Pa Flexible
I1 = pi*r1^4/4; % [m^4] second moment of area
w1 = P1/D1; % [N/m] uniformally distributed load (note w=0 for no loading);
%Now Calculate The Deflection at Height 1:
Delta_UDL_Height_PDMS_1 = [w1*H1^4/(8*E1*I1)]
Delta_UDL_Height_Elastic_1 = [w1*H1^4/(8*E2*I1)]
Delta_UDL_Height_Flexible_1 = [w1*H1^4/(8*E3*I1)]
%Now Calculate the Tip Deflection for Height 1:
Delta_tip_length_PDMS_1 = [w1*l1^3/(6*E1*I1)]*(D1)
Delta_tip_length_Elastic_1 = [w1*l1^3/(6*E2*I1)]*(D1)
Delta_tip_length_Flexible_1 = [w1*l1^3/(6*E3*I1)]*(D1)
%Add these values together:
Delta_Total_PDMS_H1 = Delta_UDL_Height_PDMS_1 + Delta_tip_length_PDMS_1;
Delta_Total_Elastic_H1 = Delta_UDL_Height_Elastic_1 + Delta_tip_length_Elastic_1;
Delta_Total_Flexible_H1 = Delta_UDL_Height_Flexible_1 + Delta_tip_length_Flexible_1;
%Now Calculate the Deflection at Height 2:
delta_UDL_Height_PDMS_2 = [w1*H2^4/(8*E1*I1)]
delta_UDL_Height_Elastic_2 = [w1*H2^4/(8*E2*I1)]
delta_UDL_Height_Flexible_2 = [w1*H2^4/(8*E3*I1)]
%Now Calculate the Tip Deflection for Height 2:
Delta_tip_length_PDMS_2 = [w1*l1^3/(6*E1*I1)]*(D2)
Delta_tip_length_Elastic_2 = [w1*l1^3/(6*E2*I1)]*(D2)
Delta_tip_length_Flexible_2 = [w1*l1^3/(6*E3*I1)]*(D2)
%Add these values tegether:
Delta_Total_H2_PDMS = delta_UDL_Height_PDMS_2+Delta_tip_length_PDMS_2
Delta_Total_H2_Elastic = delta_UDL_Height_Elastic_2+Delta_tip_length_Elastic_2
Delta_Total_H2_Flexible = delta_UDL_Height_Flexible_2+Delta_tip_length_Flexible_2
%Now Calculate the Total Deflection by Subtracting H2 from H1
Delta_Total_PDMS = Delta_Total_PDMS_H1 - Delta_Total_H2_PDMS
Delta_Total_Elastic = Delta_Total_Elastic_H1 - Delta_Total_H2_Elastic
Delta_Total_Flexible = Delta_Total_Flexible_H1 - Delta_Total_H2_Flexible
%Now Plot this data to a graph
%Finally I plot this data on a graph.
figure
hold on
plot(Delta_Total_PDMS)
plot(Delta_Total_Elastic)
plot(Delta_Total_Flexible)
legend('Flexible','Elastic','PDMS')
xlabel('Force in Newtons 0.00001<0.001')
ylabel('Deflection in metres')
  2 个评论
Rik
Rik 2020-11-17
This time I edited your question for you. Next time, please use the tools explained on this page to make your question more readable.
Robert Staruch
Robert Staruch 2020-11-17
Thanks & Apologies. Extremely Novice user here - so thanks for highlighting that. WBW

请先登录,再进行评论。

回答(1 个)

John D'Errico
John D'Errico 2020-11-17
编辑:John D'Errico 2020-11-17
MATLAB tells you exactly what is wrong, and how to fix it. (This has nothing to do with your use of pi.)
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and
the power is a scalar. To perform elementwise matrix powers, use '.^'.
Error in Partial_UDL_Clarity_Version (line 26)
I1 = (pi)*r1^4/4; % [m^4] second moment of area
The point is, MATLAB cannot perform element-wise squaring on a matrix using the ^ operator. For example, if you wish to square the elements of a vector then use .^ as the operator. See the difference here:
x = 1:3;
x.^2
ans = 1×3
1 4 9
x^2
Error using ^ (line 51)
Incorrect dimensions for raising a matrix to a power. Check that the matrix is square and the power is a scalar. To perform elementwise matrix powers, use '.^'.

类别

Help CenterFile Exchange 中查找有关 Matrices and Arrays 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by