Effacer les filtres
Effacer les filtres

Matlab question for cantilever beam

16 vues (au cours des 30 derniers jours)
Caroline
Caroline le 24 Fév 2013
Commenté : Abhishek Pawarq le 10 Fév 2022
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)

Réponse acceptée

Walter Roberson
Walter Roberson le 24 Fév 2013
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.

Plus de réponses (2)

Sven
Sven le 24 Fév 2013
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 le 25 Fév 2013
Thank you, I just was not parametizing correctly for my two values that fix helped it
  1 commentaire
Abhishek Pawarq
Abhishek Pawarq le 10 Fév 2022
Hey man can you please post the corrected code

Connectez-vous pour commenter.

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by