Question: how do i change x and y to become a vector in the if plotflag statement a the bottom???
1 view (last 30 days)
Show older comments
function [y,theta,maxd]=lab2(E,I,L,w,x,plotflag)
if 0<x & x<L
y= (-(w*(x^2))/(24*E*I))*((6*(L^2))-(4*L*x)+(x^2))
theta=(w*(L^3))/(E*I*6)
maxd=((w*(L^4))/(8*E*I))
else
error('must 0<x & x<L')
end
if plotflag==1
plot(x,y,theta,maxd);
else
error('plotflag==1')
end
0 Comments
Answers (2)
Doug Hull
on 14 Jun 2011
It looks like in the first if statement, you are expecting x and L to be scalars. This is fine. If you want x and y to be vectors in the second if statement, what would it mean to become a vector. What algoriithim would you use to create that?
Please modify your question with the expected calling syntax with sample inputs and expected outputs.
0 Comments
Walter Roberson
on 14 Jun 2011
You would change
y= (-(w*(x^2))/(24*E*I))*((6*(L^2))-(4*L*x)+(x^2))
to
y= (-(w*(x.^2))/(24*E*I))*((6*(L^2))-(4*L*x)+(x^.2))
Provided, that is, that w and E and I and L are all scalars. If they are not all scalars, you need to define what you want your equations to mean when handling multiple x.
Note that usually a statement
if 0 < x & x < L
would be a problem, but it happens to be okay in this case (likely). It would be interpreted as if it were written
if all(0 < x & x < L)
which is okay for you because you want to reject the situation where any x is out of range. On the other hand, you would have a problem if x and L are both vectors and x is not the same length as L.
0 Comments
See Also
Categories
Find more on Logical 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!