How to substitute each value of the for loop to the ode which is in the function file

2 Ansichten (letzte 30 Tage)
Thank you in advance.
I want to substitute each value obtained in the for loop one by one to the ODE as input value which is written in the function file. The below code is written for the spring mass system subjected to triangular input signal for 5 cycles.
Please help me.
----------------------------------------------Function file---------------------
function f = slider_1eqn(t,x)
% vs=.001;
n = 5; % Number of cycles.
k=20; % Stiffness in N/m
c = 70*10^-3; % Damping factor in Ns/m.
m2 = 1.2*10^-3 ; % Inertial mass in Kg.
m1 = 37*10^-3 ; % Mass of the actuator with semi-circular ball in Kg.
g = 9.81 ; % Acceleration due to gravity in m/s^2.
F = m2*g; % Friction force in N.
mu = .25; % Co-efficient of friction.
tr = 2*10^-3 ; % Rise time of the input signal.
tf = 4*10^-6 ; % Fall time of the input signal.
td = 1*10^-3 ; % Dwell time or time interval between cycles.
Vo = 200*10^-9; % Net displacement
tt = tr + tf + td; %Time period
tspan = 0:0.0001:n*tt; %time vector;
%-------------------------------Input signal generation -------------%
Y = zeros; %Initialization
for i = 1: numel(tspan)
if mod(tspan(i),(tt)) < tr
Y(i) = Vo*mod(tspan(i),tt)/tr;
sdot(i) = (Vo/tr);
elseif mod(tspan(i),tt) < tr+tf
Y(i) = Vo*(tr-mod(tspan(i),tt))/tf + Vo;
sdot(i) = Vo*(tr-1)/tf + Vo;
else
Y(i) = 0;
sdot(i) = 0;
end
end
% --------------------------
% EQUATION OF MOTION
% --------------------------
f = zeros(4,1); % a column vector
f(1) = x(2);
f(2) = (-c/m1)*(x(2) - (sdot))+ (-k/m1)*(x(1) - Y) - (F/m1);
f(3) = x(4);
f(4) = (c/m2)*(x(4) - sdot) + (k/m2)*(x(3) - Y);
-------------------------------------------------------------------------script file of the above function file--------------------------------------------------------
clear all
clc;
clf;
tic;
mu = 0.2;
n = 5;
Vo = 200*10^-9; % Net displacement
tr = 2*10^-3 ; % Rise time of the input signal.
tf = 4*10^-6 ; % Fall time of the input signal.
td = 1*10^-3 ; % Dwell time or time interval between cycles.
tt = tr + tf + td; %Time period
tspan = 0:0.0001:n*tt; %time vector;
[t,x]=ode45(@slider_1eqn,tspan,[0 0 0 0]);
yy = x(:,3);
yd = x(:,2);
figure(1);
plot(t,yy,'r','linewidth',2);
hold on
plot(t,x(:,1))
plot(t,z, 'k')
grid on

Antworten (0)

Kategorien

Mehr zu Programming 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!

Translated by