error in using syms variable in a for loop

조회 수: 4 (최근 30일)
Khaled Ahmat
Khaled Ahmat 2017년 11월 3일
편집: Walter Roberson 2017년 11월 4일
the error message is
Error using subsrefIndex exceeds matrix dimensions.
Error in sym/subsref (line 771)R_tilde = builtin('subsref',L_tilde,Idx)
Error in span_depth1 (line 143) x=vpa(x(2),3);
Error in small_loop (line 12) y=span_depth1(fc1,mu_fy,Wl,k3,k1,L);))
and this is my loop
data = importdata('case4.txt');
rerults=sym(ones(1,5));
for i=1:5
fc1 = data(i, 1);
mu_fy = data(i, 2);
Wl = data(i, 3);
k3= data(i, 4);
k1= data(i, 5);
L= data(i, 6);
y=span_depth1(fc1,mu_fy,Wl,k3,k1,L);
rerults(i)=y;
end
the function that I am calling in the loop is attached "span_depth1"
  댓글 수: 3
Walter Roberson
Walter Roberson 2017년 11월 3일
Undefined function or variable 'prctile_step'.
Khaled Ahmat
Khaled Ahmat 2017년 11월 4일
'prctile_step' is also attached

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2017년 11월 4일
편집: Walter Roberson 2017년 11월 4일
Line 94
mu_fy=mu_fy*6.895e3; % convert to SI unit ( N/m2)
is within
while mu_r>row_max
which in turn is within
while h-h1>0.001
so you keep multiplying mu_fy by 6.895e3 until eventually it overflows to inf. Everything goes downhill from there. The normrnd results become inf and nan, the row becomes 0 and NaN, the mu_r becomes NaN, that makes As into NaN, which makes y into NaN, and solve(NaN, x) becomes empty. At that point you generate an error when you try to index into the empty result.
I would point out that this kind of problem tends to occur less when you do not re-use variable names for different purposes. For example if you had used
mu_fy_si = mu_fy*6.895e3;
and then calculated with mu_fy_si, then it would have been pulling mu_fy out of the parameters each time and no overflow would have occurred. That would just have made it less optimal to have the conversion inside the double while instead of outside of both, but the problem would not have occurred.

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by