A simple algebraic which I failed to do
Show older comments
Hello friends!
Unfortunately, I have to tell you that I am unable to do a simple math I learned at intermediate school in matlab. Consider the following expression
syms dt D0 D1 D2 y y0
f=-(4*D0 - dt*D2 + 4*y*D0^2 - 4*y0*D0^2 + y^2*D2 + y0^2*D2 + 4*y*D1 - 4*y0*D1 - 2*dt*D0*D1 - 2*y*y0*D2 + 2*y^2*D0*D1 + 2*y0^2*D0*D1 - 4*y*y0*D0*D1)/(48*dt^(3/2));
I want to re-write f as in a way that each term has one single coefficient as bellow:
f = (-0.08333*D0 + 0.02083*dt*D2 - 0.08333*y*D0^2 + 0.08333*y0*D0^2 - 0.02083*y^2*D2 - 0.02083*y0^2*D2 - 0.08333*y*D1 + 0.08333*y0*D1 + 0.04167*dt*D0*D1 + 0.04167*y*y0*D2 - 0.04167*y^2*D0*D1 - 0.04167*y0^2*D0*D1 + 0.08333*y*y0*D0*D1)/(dt^(3/2));
where each coefficient is approximated using the vpa command, for instance the first coefficient is vpa(-4/48*4,4)=0.08333.
However, if I directly apply the vpa command it does not do the job correctly as you can see in bellow
vpa(f,4) = -(0.02083*(4.0*D0 - 1.0*D2*dt + 4.0*D1*y - 4.0*D1*y0 + 4.0*D0^2*y - 4.0*D0^2*y0 + D2*y^2 + D2*y0^2 - 2.0*D0*D1*dt - 2.0*D2*y*y0 + 2.0*D0*D1*y^2 + 2.0*D0*D1*y0^2 - 4.0*D0*D1*y*y0))/dt^(3/2)
which is never what I want.
Any idea?
Thanks in advance!
Babak
2 Comments
Star Strider
on 3 Jan 2022
Mohammad Shojaei Arani’s last Commnent to my now deleted Answer —
But, nobody answered my main problem "Is there a way to release the memory inside a code? something that 'pack' cannot not do". In fact, the reason I was thinking to round my big numbers was due to the fact that matlab was not able to release the memory while my code was running andto fix this extremely annoying problem I had to think how to shorten my text files, by roundin, etc., in order to be able to cope with lost memories. Later, I realized that my idea to round the numbers was not a good.
So, the main problem with matlab is what I said above. I must stress that this is an extremely big caveat for the success and let's say the survival of a programming language and if the developers of the language do not fix this problem researcher will move to other programming languages especially python which is also free!!! Remember the concept of evolution. Those species which cannot fit themselves to the environmental change and conditions will definitely go extinct!
Thanks for all of your helps and good ideas!
Babak
Star Strider
on 3 Jan 2022
Note —
I deleted my Answer because this discussion is not going anywhere.
The actual problem has to do with stochastic differential equations, not precisely the symbolic toolbox code, and should be restated to address the problem for which a solution is being requested.
.
Accepted Answer
More Answers (0)
Categories
Find more on Assumptions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
