# ODE45: IF/loop function

3 views (last 30 days)
Komal Rajana on 9 Jan 2020
Answered: Jyothis Gireesh on 12 Feb 2020
Hello,
I would like to know if its correct to write my differential equations as follow in the 'if' command in the function file. If not, please advice. I am trying to model a simple damper.
Thanks.
function [dy] = SDOF2(t, u);
dy = zeros(2,1);
m=1000; %Mass (lb.sec^2/in.)
k =100000; %Stiffness (lb/in.)
omega = sqrt(k/m); %Natural Frequency
c=2000;%Damping coefficient (lb.sec/in.)
g =386;%Acceleration of gravity (in./sec^2)
c_cr=2*m*omega; %Critical damping coefficient
xi = c/c_cr;%Damping ratio
%%Define the forcing function
% if t<=0.5
% F = sin(4*pi*t);
% else
% F =0;
F = 0;
% b=1*m*(((-omega*omega*u(1)-2*xi*omega*u(2)+F))/u(2)>0);
% end %%%%-ESTIMATION-%%%%
if ((((-omega*omega*u(1))-(2*xi*omega*u(2))+F/m)/u(2))>0)
dy(1) = u(2);
dy(2)= -omega*omega*u(1)-2*xi*omega*u(2)+F/m-0.5*m*((-omega*omega*u(1))-(2*xi*omega*u(2))+F/m);
else
dy(1) = u(2);
dy(2)= -omega*omega*u(1)-2*xi*omega*u(2)+F/m;
end
% dy(2)= -omega*omega*u(1)-2*xi*omega*u(2)+F/m;
end

Komal Rajana on 10 Jan 2020
Hi Aquatris,
Can you provide an example...I am having a horrible time with this.
thanks,
Komal
Meg Noah on 10 Jan 2020
There's a solution here on the web:
Also, I've implemented a Runge-Kutta to solve baseball motion under atmosphere drag and lift:
It's a 3-D version.
Aquatris on 10 Jan 2020
There are a lot of examples online, here is on of them.