필터 지우기
필터 지우기

ode solvers & loops for various values

조회 수: 1 (최근 30일)
harley
harley 2014년 9월 17일
편집: Jan 2014년 10월 5일
hello i have shown part of a code below. The first 'Rh' value of 70 is used to find 'EMC' & 'Kx' and the 'Kx' is used in the ode45 solver. What i am trying to do is when my 'x' value gets to say 0.5 i want to stop the ode45 solver and use the next 'Rh' value of 60 to say x=0.25 and the same with the next 'Rh' value of 50 to say x=0.1. any help would be appreciated.
Rh = [70 60 50];
EMC = (18/W)*((K1*K2*(Rh/100))/(1+K1*K2*(Rh/100)) + (K2*(Rh/100)/(1+K2*(Rh/100))));
Kx = 1/ (a0*exp(c0/(T))*e + (b0*exp(c0/(T))*v^-p)*exp(-z/(FSP-EMC)));
[t,x]=ode45('Mass_bal_func',(t0:60:tf),IMC);

채택된 답변

Michael Haderlein
Michael Haderlein 2014년 9월 17일
편집: Jan 2014년 10월 5일
The ode45 function provides the opportunity to detect "events" which would be appropriate in your case. So, put the ode45 part into a loop and run until the respective event is detected. There is an example of how to use events in the Matlab help ( http://www.mathworks.com/help/matlab/math/ordinary-differential-equations.html#f1-669698 ) and I remember another example in Cleve Moler's textbook ( http://www.mathworks.com/moler/chapters.html ).
In the two equations (EMC, Kx), you'll need to replace most of the * / by .* and ./ respectively. This way, you get all three Kx values at once.
  댓글 수: 3
Michael Haderlein
Michael Haderlein 2014년 9월 18일
I don't know, I haven't used Simulink so far. But it's not complicated to use events. Let me show it with a very small example:
odefun=@(t,x) -x; %just as example
evtfun=@(t,x) deal2(x-.25,1,0); %please see comment below
options=odeset('events',evtfun);
[t,x]=ode45(odefun,[0 10],10); %no events
[te,xe]=ode45(odefun,[0 10],10,options); %with events
figure, plot(t,x,te,xe)
deal2 is almost the same as the original deal function, however, there's a tiny difference:
function varargout = deal2(varargin)
if nargin==1,
varargout = varargin(ones(1,nargout));
else
varargout = varargin(1:nargout); %here, deal might either throw an error or pass all varargin
end
In the original Matlab deal function, the second option (after else) is a bit different. If you want details what happens here, tell me. Otherwise just accept it ;-)
harley
harley 2014년 9월 18일
thanks for that

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

추가 답변 (1개)

Mischa Kim
Mischa Kim 2014년 9월 17일
Harley, you are looking for something called events in MATLAB. Check out the section Events Location that explains how to use events in combination with ode solvers with the bouncing ball example.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by