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

댓글 수: 7

Walter Roberson
Walter Roberson 2020년 1월 9일
You need to switch to using event functions to terminate the ode45 call and then restart it.
ode45 requires that the function be differentiable. When you have an if in the function it is rarely differentiable. You need to stop at the discontinuity and restart.
Komal Rajana
Komal Rajana 2020년 1월 10일
편집: Komal Rajana 2020년 1월 10일
HI Walter,
But is it possible to specify the 'value' as >0 in the event and not '='?
thanks
Walter Roberson
Walter Roberson 2020년 1월 10일
Strictly speaking, no. However you can subtract eps(realmin) from the value as the result will be negative if the value was exactly 0.
Aquatris
Aquatris 2020년 1월 10일
It might be easier to write your own RK method for this problem.
Komal Rajana
Komal Rajana 2020년 1월 10일
편집: Komal Rajana 2020년 1월 10일
Hi Aquatris,
Can you provide an example...I am having a horrible time with this.
thanks,
Komal
Meg Noah
Meg Noah 2020년 1월 10일
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
Aquatris 2020년 1월 10일
There are a lot of examples online, here is on of them.

댓글을 달려면 로그인하십시오.

 채택된 답변

Jyothis Gireesh
Jyothis Gireesh 2020년 2월 12일

0 개 추천

It is my understanding that the differential equation is a function of “u(1)” and “u(2)”. So it is safe to assume that “u(1)” and “u(2)” are symbolic variables (or can be defined as symbolic). In this case, it may be better to use the “piecewise” function which allows conditionally defined expressions or functions.
Please refer to the following documentation link to get information on “piecewise” function

추가 답변 (0개)

카테고리

질문:

2020년 1월 9일

답변:

2020년 2월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by