Dear friends,
I have a simple question but after spending an hour I could not figur out how to fix it. So, apologies if this is a simple problem for you. As you see in bellow, I would like to write the following expression in a more compact way:
syms y y0 muY(y) dt
f=(y*diff(muY(y), y, y) - y0*diff(muY(y), y, y) + 2*muY(y)^2 + 2*diff(muY(y), y) + 2*y*muY(y)*diff(muY(y), y) - 2*y0*muY(y)*diff(muY(y), y))/dt;
More clearly, I need to re-write f in terms of (y-y0). As you see, we can do it as bellow (the command collect(f,y-y0) does not work, unfortuantely. Also, the rewrite command is limitted to soem special target functions):
f=((y-y0)*diff(muY(y), y, y) + 2*muY(y)^2 + 2*diff(muY(y), y) + 2*(y-y0)*muY(y)*diff(muY(y), y) )/dt;
which is a much nicer representation for the calculations I need to do.
Any idea?
Thanks in advance!
Babak

 채택된 답변

Paul
Paul 2021년 11월 23일

0 개 추천

Here is one approach showing step-by-step. Many could be combined. Maybe there is a simpler way?
syms y y0 muY(y) dt
f=(y*diff(muY(y), y, y) - y0*diff(muY(y), y, y) + 2*muY(y)^2 + 2*diff(muY(y), y) + 2*y*muY(y)*diff(muY(y), y) - 2*y0*muY(y)*diff(muY(y), y))/dt
f = 
syms D2Y DY
f = subs(f,diff(muY,y,2),D2Y)
f = 
f =subs(f,diff(muY,y),DY)
f = 
[numf,denf] = numden(f)
numf = 
denf = 
dt
syms dely
numf = subs(numf,y,dely + y0)
numf = 
numf = simplify(numf)
numf = 
numf = subs(numf,dely+y0,y)
numf = 
numf = subs(numf,DY,diff(muY))
numf = 
numf = subs(numf,D2Y,diff(muY,y,2))
numf = 
numf = subs(numf,dely,y-y0)
numf = 
f = numf/denf
f = 

댓글 수: 1

Mohammad Shojaei Arani
Mohammad Shojaei Arani 2021년 11월 24일
Hi Paul,
That was clever!
Since my intention for such a simplification was to reduce computational time for what I had in mind, I wonder if your recepie is suitable since it also needs quite
a lot of substitutions (given the fact that subs is slow, unfortunately, for very long
algebraic expressions I have. So, this was just a tiny part of my symbolic expressions and I just showed the tip of ice burg!). However, your idea is a good starting point for me to work on and see if I can improve it.
Thanks a lot for your precious time!
Babak

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by