Message Boards Message Boards

0
|
6980 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How to Speed Up Linear System of ODE

Posted 11 years ago
Hi All,

I am trying to solve PDE by using Method of lines. My code is very slow, I would like to run it at least n=100 to get good graph.

That means I need to solve 100X100 matrix. Can we improve my code?

Can we use                        
sol = NDSolve[{system, initc}, U[t], t]

I am attaching it..

Thanks in advance..

Selahittin..
Attachments:
POSTED BY: selahittin cinar
3 Replies
Hi, 

For linear systems of ODEs you can get an exact solution with MatrixExp[]
 (* NDSolve *)
 In[27]:= sol = DSolve[{system, initc}, U[t], t]; // AbsoluteTiming
 Out[27]= {20.089043, Null}
 (* MatrixExp *)
 In[25]:= sol2 = MatrixExp[t A].Table[1, {n + 1}]; // AbsoluteTiming
 Out[25]= {0.046551, Null}
 (* Compare *)
 i = 3;
 line1 = First[Subscript[u, i - 1][t] /. sol];
line2 = sol2[[i]];
Plot[{line1, line2}, {t, 0, 4}]
Plot[{line1 - line2}, {t, 0, 4}]

I.M.
POSTED BY: Ivan Morozov
Thanks for your suggestion, it is definetly faster than my code. Do you think it might still improve?
I am attaching my final code..
Selahittin..
Attachments:
POSTED BY: selahittin cinar
I have come up with new version of my code. Man this is much much faster. It takes a Just second..
Attachments:
POSTED BY: selahittin cinar
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract