Info
This question is closed. Reopen it to edit or answer.
How to solve this kind of differential equations ?
1 view (last 30 days)
Show older comments
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 ?
Answers (1)
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
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!