Help with loop and tracking values.

6 次查看(过去 30 天)
Hello,
I have an array full of acceleration values called B. B is calculated using the function at the bottom of the page. The rows of B correspond to the time and the columns correspond to a variable called zeta. Acceleration is calculated using these values of zeta and t that increment each iteration.
I need to figure out how to find the values of zeta which make the acceleration values in B less than or equal to 0.05 when t is greater than or equal to 0.05
How would I do this? Note: each row the time increases by 0.001 seconds, and each column of zeta increases by 0.1. Thank you.
Code:
T02=1;
tf2 = .2;
h2= 0.001;
y02 = [0, 0];
n2 = int32(ceil(tf2/h2))+1; % determine the number of steps
t2 = linspace(0, tf2, n2); % Generate a time step vector
y2 = zeros(n2,2); % Allocate the array for numerical solutions
y2(1,:) = y0'; % The first row of y is the initial condition
B = zeros(n2,21); % Allocate the array of acceleration values
zeta2 = 0:0.1:2;
for ii = 1:(n2)
for jj = 1:length(zeta2)
k1 = func2(t2,zeta2(jj),y(ii,:))';
k2 = func2(t2+h2/2,zeta2(jj),(y(ii,:)+ h2/2*k1))';
y(ii+1,:) = y(ii,:) + h2*k2;
B(ii,jj) = -10000*y(ii,1)-200*zeta2(jj)*y(ii,2)+1;
end
end
Here is func 2 if needed:
function dy = func2(t,zeta,y)
dy = [y(:,2);-10000*y(:,1)-200*zeta*y(:,2)+1];
end
  5 个评论
John Biscanti
John Biscanti 2020-9-19
I am not sure, that was me attempting to do what I needed, but I am not super skilled with MATLAB and is why I was asking.
John Biscanti
John Biscanti 2020-9-19
I think I just thought it would be comparing acceleration values and the t values that B is using

请先登录,再进行评论。

回答(1 个)

Mohith Kulkarni
Mohith Kulkarni 2020-9-24
Hi, you are trying to find the values of "zeta2" for which the values in "B" are <= 0.05 for the last 151 rows(concluded this from "t">=0.05). Refer to the below code:
t05 = find(t2==0.05); %t05 = 51, the index corresponding to time step 0.05
temp = B(t05:end,:)<=0.05; %logical matrix for B values <= 0.05 and t >= 0.05
you can retrieve zeta values for any timestep by indexing into the "zeta2". refer to below code for example:
tsq = 0.06 %time step 0.06
zeta_vals = zeta2(temp(find(t2 == tsq)-50,:))
this code should be after the loop as we are accessing the "zeta" values after computing "B" matrix values

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by