Busy- Message solving 1st order ODE
Show older comments
Hi Experts, I am new in Mathlab, and i have come across "busy" on the status bar when trying to solve simultaneous 1st order ODE. My questions are is mathlab taking time to compute or i have made an error on the code. Since i am a beginner, please simplify your response. Anyhelp is greatly appreciated. Thanks and below is the code: M-file
function dcdt= CELLULOSE(t,c)
%c(1)=c(A), c(2)=c(B), c(3)=c(C), c(4)=c(D), c(5)=c(E), c(6)=c(F), c(7)=c(G),
%c(8)=c(H), c(9)=c(I), c(10)=c(J), c(11)=c(K), c(12)=c(L), c(13)=c(M)
global K1 K2 K3 K4 TEMP R
dcdt=[-c(1)*(K1+K4); K1*c(1)-c(2)*(K2+K3); 0.95*K2*c(2); 0.25*K2*c(2); 0.20*K2*c(2);0.20*K2*c(2);0.25*K2*c(2); 0.20*K2*c(2);0.15*K2*c(2);0.1*K2*c(2);0.9*K2*c(2);0.65*K2*c(2);K3*c(2)];
Call Function:
>> clear all
>> global K1 K2 K3 K4 TEMP R
>> TEMP = 1000;
>> R=8.3141;
>> K1=(8*10^18)*exp(-46000/(R*TEMP));
>> K2=(1*10^9)*exp(-30000/(R*TEMP));
>> K3=(9.99*10^12)*exp(-10000/(R*TEMP));
>> K4=(8.10*10^7)*exp(-32000/(R*TEMP));
>> tspan =[0:400];
>> c0=[1 0 0 0 0 0 0 0 0 0 0 0 0]
c0 =
1 0 0 0 0 0 0 0 0 0 0 0 0
>> [t,x]=ode45('CELL',tspan,c0);
Please help! please
10 Comments
Walter Roberson
on 4 Dec 2011
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Jan
on 4 Dec 2011
Hi Dennis, I've formated your code for you this time.
Dennis
on 5 Dec 2011
Walter Roberson
on 5 Dec 2011
Look on the left side of your posting. You will see an icon marked "Edit" there. If you click on that, you will be put in to an editor and can edit your question.
The link I posted before shows how to format your code nicely. It was http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Dennis
on 5 Dec 2011
Walter Roberson
on 5 Dec 2011
We do not have the original differential equations, so we are not going to be able to detect whether your code implements the correct equations or not.
You are asking that the equations be evaluated at a minimum of 401 points; the time for that is going to add up.
Using the Stats option like I discussed below should allow you to see some of the progress. And of course you could reduce your number of reference points in tspan to speed matters up.
Getting rid of global by parameterizing functions should contribute _some_ speed increase, but not necessarily a lot.
Dennis
on 5 Dec 2011
Walter Roberson
on 5 Dec 2011
It is possible. Why don't you try reducing tspan to 0:1 temporarily and see how long that takes to process.
If you want to see if you are getting somewhere, you could always display the parameters that were passed to CELLULOSE
Dennis
on 5 Dec 2011
Walter Roberson
on 5 Dec 2011
Run something longer, say 0:10. Use tic before and toc afterwards to find out the elapsed time. You should be able to estimate the total required time from there.
Also, you have a lot of redundant operations. Recode CELLULOSE to have
K1c1 = K1*c(1);
K1c4 = K4*c(4);
K2c2 = K2*c(2);
K3c2 = K3*c(2);
dcdt=[-K1c1-K1c4; K1c1-K2c2-K3c2; 0.95*K2c2; 0.25*K2c2; 0.20*K2c2; 0.20*K2c2; 0.25*K2c2; 0.20*K2c2; 0.15*K2c2; 0.1*K2c2; 0.9*K2c2; 0.65*K2c2; K3c2 ];
Accepted Answer
More Answers (0)
Categories
Find more on Ordinary Differential Equations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!