Busy- Message solving 1st order ODE

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 件のコメント

Walter Roberson
Walter Roberson 2011 年 12 月 4 日
http://www.mathworks.com/matlabcentral/answers/13205-tutorial-how-to-format-your-question-with-markup
Jan
Jan 2011 年 12 月 4 日
Hi Dennis, I've formated your code for you this time.
Dennis
Dennis 2011 年 12 月 5 日
Hi Jan,
Where can i find the code?? Please help
Walter Roberson
Walter Roberson 2011 年 12 月 5 日
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
Dennis 2011 年 12 月 5 日
Walter, Is that the code for my solution?? Did you find any erron on that code??
Walter Roberson
Walter Roberson 2011 年 12 月 5 日
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
Dennis 2011 年 12 月 5 日
Hi Walter, Is it possible that the problem that i stated takes more then few hours to solve??
Walter Roberson
Walter Roberson 2011 年 12 月 5 日
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
Dennis 2011 年 12 月 5 日
Walter, you are awesome man. It worked for tspan 0:1, that means my code is correct, i just need to wait. or may be get a faster computer. what you think??
Walter Roberson
Walter Roberson 2011 年 12 月 5 日
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 ];

サインインしてコメントする。

 採用された回答

Walter Roberson
Walter Roberson 2011 年 12 月 4 日

0 投票

It is recommended that you do not use "global". The alternative is http://www.mathworks.com/help/techdoc/math/bsgprpq-5.html
To get a better idea of what is going on in your routine, use odeset() to create an options structure that you pass to ode45. In particular you could ask for Stats http://www.mathworks.com/help/techdoc/ref/odeset.html#f92-1016858

その他の回答 (0 件)

カテゴリ

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by