Index exceeds the number of array elements (1).
조회 수: 1 (최근 30일)
이전 댓글 표시
I=(b*h^3)/12; % Inercia se mide en cm^4, Variable de salida
x=0:0.1:L; %Vector
def=zeros(length(x),length(F)+1);
for j=1:length(F)
for i=1:length(x)
if x(i)>=a(j)
def(i,j)=((F(j)*b(j))/(6*L*E*I))*((L/b(j))*(x(i)-a(j))^3-x(i)^3+(L^2-b(j)^2)*x(i));
else
def(i,j)=((F(j)*b(j))/(6*L*E*I))*(-x(i)^3+(L^2-b(j)^2)*x(i));
end
end
end
def(:,end)=sum(def,2);
me ocurre luego del else, esa formula, me da error por algunar razon, nesecito ayuda, ya que es por una tarea
댓글 수: 1
Walter Roberson
2023년 9월 27일
Approximate translation:
It happens to me after the else, that formula, it gives me an error for some reason, I need help, since it is for a task
답변 (1개)
Walter Roberson
2023년 9월 27일
이동: Walter Roberson
2023년 9월 27일
format long g
h = rand() %guess
L = rand() * 3 %guess
F = sort(rand(1,7)) %guess
a = rand(size(F)) %guess
b = rand(size(F)) %guess
E = rand() * 10 %guess
I=(b*h^3)/12; % Inercia se mide en cm^4, Variable de salida
x=0:0.1:L; %Vector
def=zeros(length(x),length(F)+1);
for j=1:length(F)
for i=1:length(x)
if x(i)>=a(j)
def(i,j)=((F(j)*b(j))/(6*L*E*I))*((L/b(j))*(x(i)-a(j))^3-x(i)^3+(L^2-b(j)^2)*x(i));
else
def(i,j)=((F(j)*b(j))/(6*L*E*I))*(-x(i)^3+(L^2-b(j)^2)*x(i));
end
end
end
def(:,end)=sum(def,2);
We deduce that b must be a vector at least as long as F is, or else you would not index b(j) in the code.
But if b is a vector then since I = b*h^3 then I would have to be a vector the same size as b.
But you have / (6*L*E*I) and with I being a vector, the denominator would have to be a vector -- unless, that is, that L*E happens to be a row matrix and b happens to be a column matrix, in which case L*E*I could be a request for algebraic multiplication that collapsed two vectors into a scalar. But L is used as the upper bound for the for j loop, so it is probably not a vector... and we see no other indication that E might be a vector. Oh and the code has L^2 which could only work if L is a square array (including scalar) because ^ is matrix power, not element-by-element power
Could it be that ./ is needed instead of / ? If we work though using the fact that L must be a square matrix for L^2 to be valid, we can see that if 6*L*E*I is non-scalar and ./ is used, then the right hand side of the assignments to def(i,j) could not possibly be scalar.
Nothing much makes sense unless b and F are both scalars even though they are indexed in the code.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrices and Arrays에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!