Loop until Matrix value exceeds value
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Jan
am 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?
Antworten (1)
dpb
am 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);
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 Kommentare
Siehe auch
Kategorien
Mehr zu Structural Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!