Loop until Matrix value exceeds value
3 次查看(过去 30 天)
显示 更早的评论
I have a script for truss analysis. The calculation is set up Ax=b. A is the govenring equations from the truss anaylsis while x is m. Thus b is the stresses in the members depending on m. m ranges from values 1-7. i need to make a loop that ends the calulations after a certain value of matrix b is met and then displays the previus iteration as "max allowable mass". my issue is designating that "a value inside b" > given value. and having the loop re-run for the acceptable tolerances.
3 个评论
Jan
2021-9-13
If A ia [9 x 1] vector and x is [1 x 7], A * x is a [9 x 7]. How can this be given as 9 different values? Over which calculation do you want to run a loop?
回答(1 个)
dpb
2021-9-13
% pseudo code, salt to suit...
A=[...]; % initialize A here
maxB=60; % the test value
for x=1:7
B=A*x; % compute B
if all(B)<=maxB % everything AOK so far...
fprintf(['X=%d, B[]=' repmat(numel(B),'%f.2 ') newline],X,B);
end
end
The above prints every time the condition is met rather than waiting unitl it fails and then backing up one level -- that's doable, takes a little more logic to save the previous values as well so I took the easy way out here.
The key MATLAB point here is the use of any and/or all to make the logic test -- read the documentation for them to see why.
I don't know the problem your'e trying to solve, of course, but it seems to me that rather than use the multiples of 1:N it would make more sense to solve the system to find the critical mass value instead.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structural Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!