Info

This question is closed. Reopen it to edit or answer.

How to solve this kind of differential equations ?

1 view (last 30 days)
P K
P K on 13 Jan 2019
Closed: MATLAB Answer Bot on 20 Aug 2021
I am attaching a image which represent a system. The variables here are
1) n 2) P_n 3) r 4) t
I was wondering how can we solve this kind of differentiation in matlab.I have tried myself but i think there is some better approch which i dont know.It is a initial value problem. I know the initial values of P_n 's.
Any idea how to do it ?
  9 Comments
P K
P K on 16 Jan 2019
@ Jan. I thinks i am not able to make my point.Thanks for your comment. I would try myself.
P K
P K on 17 Jan 2019
This would answer my question
https://in.mathworks.com/matlabcentral/answers/438438-solving-many-linear-differential-equations-through-ode-solver

Answers (1)

John D'Errico
John D'Errico on 16 Jan 2019
I don't do consulting via e-mail. I also explicitly ask people not to contact me directly (as you did), as that will just get them into the habit of contacting me every time they have any question at all. And yes, that happens.
I'll point out that since you want an analytical solution, then you need to use syms. So using "syms and a loop", (not sure what you mean by that, but writing a loop to do this would be trivially easy, and the loop itself would run efficiently enough) only means that you want to find a way to write this without a loop. The pertinent question then becomes, who cares? Why should you care?
If a an analytical solution exists at all (and that has still not been shown to be a fact), for a problem with potentially on the order of 100 equations, the solution time will be massive compared to the time required to pose the problem. So you are surely pre-optimizing. And one golden rule of computation is to not pre-optimize. Don't waste programmer time for something that is irrelevant, merely for the sake of programming elegance.
So even for only 3 equations, I've not checked, but even there I don't know if an analytical solution exists. For dozens of equations or more, again, just create the equations anyway you want to do it, but I'd bet that the solve time is the massive part. Only if the scheme you came up with to actually create those equations is so incredibly inefficient that merely creating them is dominating the time required to solve them would you care. And if that is the case here, then you need to learn some basics of MATLAB, and perhaps the symbolic toolbox and vectors. (You have shown us nothing in that respect, so I cannot know. All you said is "loops".)
The very first thing you need to do is verify that an analytical solution exists at all for any general n. If dsolve cannot find it, then don't waste time writing elegant code to pose a problem you cannot solve. And even if you can find a solution, check the time required for the solve. Then think about how long it takes MATLAB to execute the for loop
for i = 1:n
end
even a nested loop is still fast.
  1 Comment
P K
P K on 16 Jan 2019
Hello John.Sorry but I didn't mean to trouble you.
I mailed you only the link of this question and nothing else. I did so to bring your notice,as you had comment on it previosly.
You have said "Don't waste programmer time for something that is irrelevant, merely for the sake of programming elegance". Iam not wasting time.I am a student and don't have programming background. I have started using matlab only from last 6 months. So I thought this forum is the right place to start interacting with MORE EXPERIENCED peoples, like you, and learn.
I would take care and not mail.
Thanks for your valued suggestions.

Community Treasure Hunt

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

Start Hunting!