Question: how do i change x and y to become a vector in the if plotflag statement a the bottom???
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(2 个)
Doug Hull
2011-6-14
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 个评论
Walter Roberson
2011-6-14
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!