필터 지우기
필터 지우기

Question: how do i change x and y to become a vector in the if plotflag statement a the bottom???

조회 수: 2 (최근 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

답변 (2개)

Doug Hull
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.

Walter Roberson
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.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by