필터 지우기
필터 지우기

ode45 too long to solve

조회 수: 3 (최근 30일)
tony
tony 2013년 1월 24일
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
Jan
Jan 2013년 1월 24일
편집: Jan 2013년 1월 24일
Please answer the questions for clarifications instead of posting new questions about the same problem. See http://www.mathworks.com/matlabcentral/answers/59695-loop-for-with-ode45 .
And please, tony, format your code properly. Now Walter did this for you.

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

답변 (2개)

Jan
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.

tony
tony 2013년 1월 24일
sorry , but here it's the same problem. My last problem is solved. But here the problem is a little more complex.
  댓글 수: 1
Jan
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 CenterFile Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by