Filter löschen
Filter löschen

Help with loop and tracking values.

2 Ansichten (letzte 30 Tage)
John Biscanti
John Biscanti am 19 Sep. 2020
Beantwortet: Mohith Kulkarni am 24 Sep. 2020
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 Kommentare
John Biscanti
John Biscanti am 19 Sep. 2020
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 am 19 Sep. 2020
I think I just thought it would be comparing acceleration values and the t values that B is using

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mohith Kulkarni
Mohith Kulkarni am 24 Sep. 2020
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

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by