Matlab question for cantilever beam

조회 수: 3 (최근 30일)
Caroline
Caroline 2013년 2월 24일
댓글: Abhishek Pawarq 2022년 2월 10일
My homework assignment involves graphing the deflection equation of a beam. I am fairly new to matlab and i am coming across an error in how i am writing the codes since i am not using matrices
Here is my code and i get this error when ran
??? Subscript indices must either be real positive integers or logicals.
Error in ==> inertia at 38
U(x)= F./E.*I.*(x.^3-3.*L.*x.^2);
E = input('Youngs Modulus:');
r = input('Enter 1 for circular cross section, Enter 2 for rectangular cross section') ;
if(r==1)
d = input('Dimater:');
I = (pi*(d/2)^4)/4;
elseif(r==2)
b = input('Width of Beam:');
h = input('Height of Beam:');
I = (b*h^3)/12;
end
%Above runs how to find the I of cross section this will be used for figure
%1 and 2
%now need to create code to input the length of beam and where loads can be
%like element stiffness matrix
L = input('Length of beam:');
F = input('Force');
j = input('Enter 1 if force is at end of beam, Enter 2 if force is in middle of beam') ;
if (j==1)
w = F*L^2/3*E*I ; %this give max deflection
elseif (j==2)
a = input('Location from support of point');
w = F*a^2/6*E*I*(a-3*l);
end
%above found the max deflection for the two different cases, now code needs
%to be written so i can graphically show these inputs i also need to add in
%how to see the values
%here right formula for graph and take values from above to plot it
%using equation for elastic curve
str=['deflection: ', num2str(w)];
disp(str)
x= 0:0.1:L;
U(x)= F./E.*I.*(x.^3-3.*L.*x.^2);
y = 0:U(x):w;
plot(x,y)

채택된 답변

Walter Roberson
Walter Roberson 2013년 2월 24일
Change your line
U(x)= F./E.*I.*(x.^3-3.*L.*x.^2);
to
U = F./E.*I.*(x.^3-3.*L.*x.^2);
However, I do not know what U represents to you (you have not comment about it), so I cannot figure out how to correct your 0:U(x):w expression for y. My speculation is that you want
y = U;
but I do not know.

추가 답변 (2개)

Sven
Sven 2013년 2월 24일
Hi Caroline,
The problem is here:
x= 0:0.1:L;
U(x)= F./E.*I.*(x.^3-3.*L.*x.^2);
I think you simply mean:
x= 0:0.1:L;
U= F./E.*I.*(x.^3-3.*L.*x.^2);
You'll note (if you run your code one line at a time) after the first line that x is an array starting at 0 and with lots of elements up to the value of L. It makes no sense for the xth element of U to be accessed in this context.
And when you plot, I think you're just trying to do this:
plot(x,U)
... I'm not quite sure what your assignment to y actually means.
Did this help you out?

Caroline
Caroline 2013년 2월 25일
Thank you, I just was not parametizing correctly for my two values that fix helped it
  댓글 수: 1
Abhishek Pawarq
Abhishek Pawarq 2022년 2월 10일
Hey man can you please post the corrected code

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by