Question: how do i change x and y to become a vector in the if plotflag statement a the bottom???
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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 comentarios
Respuestas (2)
Doug Hull
el 14 de Jun. de 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 comentarios
Walter Roberson
el 14 de Jun. de 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 comentarios
Ver también
Categorías
Más información sobre Get Started with MATLAB en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!