How can I obtain the derivative of a vector? Displacement-Velocity but what about acceleration? I am using the space state formulation
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Fedilberto Gonzalez
am 19 Dez. 2021
Kommentiert: Joe
am 10 Jan. 2023
Dear Sir/Madam,
I am using space state formulation to obtain the displacement and velocity for a SDOF system under free vibration. The code is below. Could you kindly let me know how to estimate the acceleration, please?
Thank you!
clc; %command window
clear all;%clear workspace
m = 80; %Defining mass of SDOF system
k = 10000;%Defining stiffness of SDOF system
global m k
dt = .02; %Defining Time Step:
t = 0:dt:4;% Defining time vector.
y0 = [0.085 0.1]; %initial vel and disp [vel disp] %velocity.
[tsol, yvectorl] = ode45('statespace',[0:dt:4],y0); order.
%%function statespace
function dy = testode1(t,y)
global m k
%dy(1) = -k*y(2)/m
%dy(2) = y(1)
dy=[-k*y(2)/m;y(1)];
%% fin function state space
%%plot
figure()
plot(t,yvector(:,2)) %Disp.(2)
figure()
plot(t,yvector(:,1)) %Vel. (1)
0 Kommentare
Akzeptierte Antwort
Mitchell Thurston
am 19 Dez. 2021
(Altered the code provided so that it ran properly)
clc; %command window
clear;%clear workspace
close all; % close figures
m = 80; %Defining mass of SDOF system
k = 10000;%Defining stiffness of SDOF system
dt = .02; %Defining Time Step:
t = 0:dt:4;% Defining time vector.
y0 = [0.085; 0.1]; %initial vel and disp [vel disp] %velocity.
[tsol, yvectorl] = ode45(@testode1,t,y0);
%%plot
figure()
plot(tsol,yvectorl(:,2)), title("Displacement") %Disp.(2)
figure()
plot(tsol,yvectorl(:,1)), title("Velocity") %Vel. (1)
% THIS NEEDS TO GO AT THE END OF THE FILE
%%function statespace
function dy = testode1(t,y)
global m k
dy=[-k*y(2)/m;y(1)];
end
Because you know the state space, you can find the acceleration based on the state:
accel_vector = yvectorl(:,2).*(-k/m);
but for it to apply more generally, you can just use the diff function
accel_vector = diff(yvectorl(:,1));
2 Kommentare
Walter Roberson
am 19 Dez. 2021
diff() assumes uniform time steps, and so would not normally be usable for ode45() results. It would be in this case because a time vector with equal steps was passed in. On the other hand, diff() would scale everything incorrectly becuase it does not know the time interval. And you would end up with one fewer entry than the original.
gradient() passing in the time and values will take the time step into account, and will use more accurate central differences except at the first and last point.
Weitere Antworten (1)
Walter Roberson
am 19 Dez. 2021
Bearbeitet: Walter Roberson
am 19 Dez. 2021
estimated_acceleration = gradient(t, yvector(:,1));
By the way, please see http://www.mathworks.com/help/matlab/math/parameterizing-functions.html for information on how to stop using global.
2 Kommentare
Joe
am 10 Jan. 2023
Hello, this is a little dated but I have a question regarding the solution and statespace formulation. Why is it that when the displacement from above solution is differentiated wrt time, the velocity vector derived is not same as the velocity vector from the state space solution?
That is, diff(yvector(:,2))./diff(t) is not equal to yvector(:1). Thanks in advance
Siehe auch
Kategorien
Mehr zu Vibration Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!