Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Help with loop and tracking values.

1 visualización (últimos 30 días)
John Biscanti
John Biscanti el 19 de Sept. de 2020
Cerrada: John D'Errico el 19 de Sept. de 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.
I am specifically talking about the second for loop with ii:n2 and jj being the length of zeta
Code:
clc
clear
T0=1;
tf = .01;
h= 0.001;
y0 = [0, 0];
n = int32(ceil(tf/h))+1; % determine the number of steps
t = linspace(0, tf, n); % Generate a time step vector
y = zeros(n,2); % Allocate the array for numerical solutions
y(1,:) = y0'; % The first row of y is the initial condition
A = zeros(n,21); % Allocate the array of acceleration values
%----------------------------------------------------------------------
% TODO: Implement the loop
%----------------------------------------------------------------------
zeta = 0:0.01:0.05;
for ii = 1:(n)
for jj = 1:length(zeta)
k1 = func2(t,zeta(jj),y(ii,:))';
k2 = func2(t+h/2,zeta(jj),(y(ii,:)+ h/2*k1))';
y(ii+1,:) = y(ii,:) + h*k2;
A(ii,jj) = -10000*y(ii,1)-200*zeta(jj)*y(ii,2)+1;
end
end
%Amax = max(A,[],'all') %Amax
%A(11,6) %sanity check
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
end

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by