Hello! Imagine I have a very long equation with many variables, like the example bellow
eq = 0.001*(wr + wl) + 2*z + 1.5*z == -2wp
How can I force matlab to make the following change of variable:
Y = 0.1*(wr + wl) ?
I mean, I need matlab to group the equation (eq) into 0.1*(wr + wl) and replace those terms by Y. In the example above, the result should be:
eq = 0.01*Y + 2*z + 1.5*z == -2wp
Thanks a lot!

 채택된 답변

madhan ravi
madhan ravi 2018년 11월 24일
편집: madhan ravi 2018년 11월 24일

0 개 추천

>> syms wr wl z wp Y
eq = 0.001*(wr + wl) + 2*z + 1.5*z == -2*wp
eq=subs(eq,0.001*(wr+wl),0.01*Y)
eq =
wl/1000 + wr/1000 + (7*z)/2 == -2*wp
eq =
Y/100 + (7*z)/2 == -2*wp
>> vpa(eq)
ans =
0.01*Y + 3.5*z == -2.0*wp
>>

댓글 수: 3

Hello madhan! Thank you for your answer! I thought about this solution too! The only problem here is that i need to know the term 0.001*(wr + wl) in order to make the exact substitution. However, if my equation is too long, I would need to make the substitution for each individual term. Let's take another equation as an example:
syms wr wl z wp Y x
eq = 0.001*(wr + wl) + sin(2*x)*2.5*(wr + wl)^2 + 0.9*(wr + wl)^2 + 2*z + 1.5*z == -2*wp
subs(eq,0.001*(wr+wl),0.01*Y)
In this case, subs(eq,0.001*(wr+wl),0.01*Y) would only replace the first term. What I wanna knoe is if there is a generic way to force matlab replace Y = 0.1*(wr + wl) in any situation.
Your idead pointed me to the right solution! Thanks a lot! I just need to do the opposit:
syms wr wl z wp Y x
eq = 0.001*(wr + wl) + sin(2*x)*2.5*(wr + wl)^2 + 0.9*(wr + wl)^2 + 2*z + 1.5*z == -2*wp
subs(eq,(wr+wl),Y/0.1)
madhan ravi
madhan ravi 2018년 11월 24일
편집: madhan ravi 2018년 11월 24일
Anytime :)

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

추가 답변 (0개)

제품

릴리스

R2018b

태그

Community Treasure Hunt

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

Start Hunting!

Translated by