Loop until Matrix value exceeds value

3 次查看(过去 30 天)
Buster
Buster 2021-9-13
回答: dpb 2021-9-13
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 个评论
Buster
Buster 2021-9-13
Essentially i only have A=9x1 and x=1:7. B is the resulting values of A*x and they are given as 9 different values which is what i need. Basically i need a loop to run through the caluclation of A*x=B until a single value of the 9 given by B is over 60. once any of said values hits 60 i need the loop to stop and display all 9 B values that are accepted and the x value that gives these B values that are less than the tolerance of 60. does this help?
Jan
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
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.

类别

Help CenterFile Exchange 中查找有关 Structural Analysis 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by