Determine the maximum force, of your 1000 random forces, for which the cylinder will not fail. Determine the minimum force, of your 1000 random forces, for which the cylinder will fail. Output both values to the workspace.

2 views (last 30 days)
Originally a matrix is made using: F=35.*rand(1000,1)
Now the force can't exceed the value of this expression: (75*(pi*(.5.^2)/4))
This means the force can't exceed appx. 14.7N but the matrix made has random forces from 0-35N. I am trying to use an if or while or for statement, example: F_max=max(F) F_max<(75*(pi*(.5.^2)/4)) while j=F_max
if F<75*(pi*(.5.^2)/4)
disp('F_max=ans')
end
end
or
if F<(75*(pi*(.5.^2)/4))
X=max(F)
end
But when the max(F) is found, it does not satisfy the previously stated condition. I tried to make it a string but this still found max of the total. How can I use a statement, that will utilize the condition to find the max?

Accepted Answer

Roger Stafford
Roger Stafford on 10 Feb 2014
I assume you are in the process of learning how to code in matlab or perhaps in any computer language. If so, it is useful to think of such problems in terms of what you would do if you carried out the processing manually. Picture two cans labeled "pass" and "fail". You would pick up these random numbers one by one, figuratively speaking, and examine each one. The ones that were greater than your fail figure you would place in the "fail" can and the others in the "pass" can. Then when you were finished with that, you would rummage through the "fail" can to find the smallest number in it and the "pass" can to find the largest number there, and you would have your answers.
Now you need to translate all that hypothetical action into matlab code. Here are some hints. (1) First you need 1000 random numbers and you already have that in your code. (2) "Pick up these random numbers one by one." This suggests a for-loop construct which runs through this list of random numbers one at a time to examine them. (3) Decide which "can" each number goes in. That is surely done using matlab's logical inequality operator. (4) Place it in the "fail" or "pass" can accordingly. Here is where the if-else-end construct can be used to place the numbers at the end of one of two possible vectors which act as your "cans". (5) Afterwards rummage through the cans. This is where the 'max' and 'min' functions can be used. Apply one or the other of them to the appropriate can (vector.)
If you follow that outline faithfully, you will have a working program to accomplish the desired end. It is far from the most efficient code, but it will do for now. Later you can learn how to make what appears to be a simultaneous comparison of all the random numbers in one line of code and accompanied by 'max' and 'min' operations, but you can put that off for a future time.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!