improve my program ode45
Info
This question is closed. Reopen it to edit or answer.
Show older comments
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 Comment
Walter Roberson
on 27 Jan 2013
Answers (0)
This question is closed.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!