problem about the scipt
Show older comments
clear all
l = 25
E = 200*10^9
I = 350*10^-6
w = 6*10^3
x = input('enter length of the beam')
if (x>=0)&(x<= l/2),
y = -w*x/384*E*I *(16*x^3-24*l*x^2+9*l^3);
elseif
(x>=l/2)& (x<= l);
y = -w*x/384*E*I*(8*x^3-24*l*x^2+(17*l^2)*x-l^3)
end
Why I can not get the value of y? How to get it?
10 Comments
pietro
on 27 Apr 2014
Do you get any error from the compiler? I have run the code and it works on my computer
Geoff Hayes
on 27 Apr 2014
What value of y are you expecting? What does this code do? Note that you seem to be conditioning on whether or not x is within a certain range: between 0 and 25/2 or between 25/2 and 25 (where l=25). So y won't be set if your input is greater than 25.
Your else statement is not quite correct. The condition should be:
elseif (x>=l/2) && (x<= l)
rather than just the else with a condition that is not "attached" to anything.
Shi Yuhao
on 28 Apr 2014
Geoff Hayes
on 28 Apr 2014
The y variable is always being set in your above code which may or may not be correct given what appears to be a condition in the else block when in fact it the condition should be part of an elseif statement. (This is noted in the above comment and in the answer from Image Analyst.) Could you verify this condition and then correct your above code?
As for defining x you have set l to be 25. So that means that as long as the input value (which is x) is between 0 and 25, then the y will be set to something. If y is being incorrectly set, then the code (or equation for y) has to be changed by you.
Geoff Hayes
on 28 Apr 2014
What is your value of x? What is the resulting y?
Shi Yuhao
on 28 Apr 2014
Geoff Hayes
on 28 Apr 2014
What do the following variables represent, and please include the units for each: l, E, I, w and y? I realize that y is the deflection of the beam but what are the units for it?
Is E the modulus of elasticity? Is I the area moment of inertia?
Based on some notes at deflection, your product of E*I should be in the denominator and not in the numerator. i.e. instead of
-w*x/384*E*I
should this be
-w*x/(384*E*I)
What are the equations that you are trying to translate into MATLAB code?
Is the real problem that you are not getting the y that you expect?
Shi Yuhao
on 28 Apr 2014
Geoff Hayes
on 28 Apr 2014
What are you asked to loop over? There is no loop in your above code. As well, please verify your equation. Perhaps post it here and we can help make sure that you have coded it up (in MATLAB) correctly.
Accepted Answer
More Answers (0)
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!