Azzera filtri
Azzera filtri

Index exceeds the number of array elements (1).

1 visualizzazione (ultimi 30 giorni)
I=(b*h^3)/12; % Inercia se mide en cm^4, Variable de salida
Unrecognized function or variable 'b'.
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 Commento
Walter Roberson
Walter Roberson il 27 Set 2023
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

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 27 Set 2023
Spostato: Walter Roberson il 27 Set 2023
format long g
h = rand() %guess
h =
0.417948953996748
L = rand() * 3 %guess
L =
1.32388434608202
F = sort(rand(1,7)) %guess
F = 1×7
0.11991245962135 0.29570499617597 0.415964024718241 0.693165544877611 0.702821324822456 0.725661942718158 0.98651689150941
a = rand(size(F)) %guess
a = 1×7
0.602261901516086 0.0802892332996559 0.115357856160582 0.94879157875644 0.167653007634221 0.304942826817748 0.894580810077379
b = rand(size(F)) %guess
b = 1×7
0.0640251615177048 0.154027841888933 0.480714567113372 0.629086724012843 0.00769341226588571 0.585933615959605 0.545553092415119
E = rand() * 10 %guess
E =
2.42930294432061
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
Error using /
Matrix dimensions must agree.
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.

Categorie

Scopri di più su Matrices and Arrays in Help Center e File Exchange

Tag

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by