[英]nonnegative option in a function of an ODE
As it is specified in the title I need to force a function to be always positive (if it runs into negative it has to equal 0). 正如标题中所指定的那样,我需要强制某个函数始终为正(如果遇到负数则必须等于0)。 This function is inside an ODE:
此功能在ODE内部:
This is the script from where I call the ODE: 这是我称为ODE的脚本:
clear
t=[0,276];
Tie=0.3;
mumax=2;
Qmin=1;
X0=[4,2];
[t,X]=ode45(@(t,X) odeset(mumax,Qmin,Tie,X),t,X0);
This is the function that I want to keep always positive 这是我要保持积极的态度
function [ func2 ] = func2 (mumax,Qmin,Q)
func2=mumax*(1-Qmin/Q);
end
and this is the ODE 这是ODE
function [ dXdt ] = odeset(mumax, Qmin, Tie,X)
dXdt=zeros(2,1);
dXdt(1)=func2(mumax,Qmin,X(1))-X(2)*Tie;
dXdt(2)=func2(mumax,Qmin,X(1))-X(2)*Tie;
end
Change func2
's output to 将
func2
的输出更改为
function [ out ] = func2 (mumax,Qmin,Q)
out=max(mumax*(1-Qmin/Q),0);
end
This will force the output to be positive or Zero. 这将强制输出为正或零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.