MATLAB Answers

Loop until Matrix value exceeds value

5 views (last 30 days)
Robert Herrell
Robert Herrell on 13 Sep 2021
Answered: dpb on 13 Sep 2021
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.
Jan on 13 Sep 2021
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?

Sign in to comment.

Answers (1)

dpb on 13 Sep 2021
% 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);
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.


Community Treasure Hunt

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

Start Hunting!