I am looking to create a table of data calculated within a while loop to get values that satisfy certain requirements.
4 views (last 30 days)
Show older comments
I am in the process of completing a project where I need to collect data that matches certain specifications in regards to solutions over an interval. I am able to properly set up how to calculate each equation and piece of the problem, but I am struggling to find a way to place everything in an array, table, etc. Everything I have seen online in regards to this does not work due to the nature of the problem having varying results, and I am rather lost as to where to go.
4 Comments
Voss
on 24 Mar 2022
Is the main problem at this point about how to select/record which sets of D, M, R meet the condition? Or is it more about how to keep track of all the D, M, R as the while loop runs? Or both? Or something else?
Maybe you can attach the code?
Answers (1)
Voss
on 24 Mar 2022
Please see below. all_results is the matrix I put in to store the M and r each time the condition is satisfied. (I also adjusted the initial k value and the while condition in order to get some results with relatively few iterations, for demonstration - you can change that back to how it was.)
m = 2540 ; % The mass of Orion in Kilograms
Y = 0.01 ; % Amplitude determined by equation of motion y(t)
w = 50*pi ; % Omega, the angular velocity value in Radians/sec
wn = 1 ; % Starting natural Frequency
g = 98 ; % The maximum acceleration experienced in m/s^2
st = 0.0017; % The maximum standard deflection in m
stcalc = st +1 ;
r = 1 ; % frequency ratio start
d = 0.01; % damping ratio start
Xmin = 1;
Xcalc = 1.5 ;
M = 0 ; %Magnitude Ratio
% Value for the Stiffness Coefficient
Row = 0 ;
k = 200000000 ; % Minimum value for Spring Coefficient in N/m
count = 0;
% going to store the results in a matrix with 2 columns,
% so initialize it to have zero rows at first:
all_results = zeros(0,2);
while k < 200000000+100*1000%300000000
count = count + 1;
%Numerator = (k^2)+((c*w)^2); % Numerator of Equation
%Denominator = (((k-m*(w^2))^2)+(c*w)^2); %Denominator of Equation
wn = sqrt(k/m) ;
r = w/wn ;
c = d*(2*sqrt(m*k)) ;
Numerator = 1+((2*d*r)^2) ;
Denominator = ((1-(r^2))^2)+((2*d*r)^2) ;
Xcalc = Y * sqrt(Numerator/Denominator) ;
stcalc = (m*g)/k ;
%Xcalc = Y*sqrt(((k^2)+(c*(w^2))/((k-m*(w^2))+((c*w)^2)))) ;
if stcalc < st
if Xmin > Xcalc
Xmin = Xcalc ;
cmin = c ;
kmin = k ;
end
M = Xcalc/Y ;
% now store the current M and r in the all_results matrix
all_results(end+1,:) = [M r];
end
k = k + 1000 ;
end
% make the stored M and r into a table t:
t = array2table(all_results,'VariableNames',{'M','r'})
0 Comments
See Also
Categories
Find more on Logical 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!