ode45 too long to solve
3 次查看(过去 30 天)
显示 更早的评论
hi , i'm trying to solve an ode , my program works but it makes 1 hours... and o don't understand why
Here is my fonction to define my ode :
function dy=f_mixte(t,y)
global Q b K n E sg0 epoint C1 C2 D1 D2
f=abs(y(1)-y(3)-y(4))-Q*(1-exp(-b*y(2)))-sg0;
if f<0
dy(2)=0;
else
dy(2)=(f/K).^n;
end
dy(5)=sign(y(1)-y(3)-y(4));
dy(1)=E*(epoint-dy(5));
dy(3)=C1*dy(5)-D1*y(3)*dy(2);
dy(4)=C2*dy(5)-D2*y(4)*dy(2);
dy=dy';
end
And here my main function :
global Q b K n E sg0 epoint C1 C2 D1 D2 sigma0
b=5;
Q=-150 ;
E=140000;
sigma0=200;
K=800;
n=6;
epoint=0.001;
sg0=200;
C1=300000;
C2=25000;
D1=2000;
D2=200;
[T,a]=ode45('f_mixte',[0 10],[0 0 0 0 0])
thanks for your help :)
[Merged information from duplicate Question]
hi !
I would like to improve my program, i'm want it be faster and make better virtual mode memory management :
global Q b K n E sg0 epoint C1 C2 D1 D2
b=5;
Q=-150 ;
E=140000;
sigma0=200;
K=800;
n=6;
epoint=0.001;
C1=300000;
C2=25000;
D1=2000;
D2=200;
sg0=200;
%Resolution
[t,y]=ode45('f_mixte',[0 10],[0 0 0 0 0]);
sigma1=y(:,1);
ep1=y(:,5);
e1=ep1+sigma1/E;
tic
hold on
for w = 0:100
Ti=10;
Tf=30;
L=length(y);
epoint=-epoint;
[t,y]=ode45('f_mixte',[Ti Tf],[y(L,:)]);
Ti=Tf;
Tf=Ti+20;
sigma2=y(:,1);
ep2=y(:,5);
e2=ep2+sigma2/E;
L=length(y);
plot(e1,sigma1,e2,sigma2)
end
hold off
toc
and my main function
function dy=f_mixte(t,y)
global Q b K n E sg0 epoint C1 C2 D1 D2
R=Q*(1-exp(-b*y(2)));
f=abs(y(1)-y(3)-y(4))-R-sg0;
if f<0
dy(2)=0;
else
dy(2)=(f/K)^n;
end
dy(5)=sign(y(1)-y(3)-y(4))*dy(2);
dy(1)=E*(epoint-dy(5));
dy(3)=C1*dy(5)-D1*y(3)*dy(2);
dy(4)=C2*dy(5)-D2*y(4)*dy(2);
dy=dy';
end
1 个评论
回答(2 个)
Jan
2013-1-24
I've explained problems with integrating discontinuous functions in your former thread http://www.mathworks.com/matlabcentral/answers/59582-ode45-errer-input-argument-y-is-undefined already. Asking equivalent questions repeatedly while ignoring answers does not help to find a solution.
0 个评论
tony
2013-1-24
1 个评论
Jan
2013-1-28
You still have a discontinuity in the function, which you want to integrate. My former comment explained, why this can lead to a very slow and very inaccurate calculation. Now you ask for a very slow calculation, therefore I'm not convinced, that the former problem is solved.
And if it is really solved, please explain this in the other thread also, such that nobody wastes time by creating a new suggestion anymore. Tony, please use this forum with care and respect.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Ordinary Differential Equations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!