making a substitution
조회 수: 8 (최근 30일)
이전 댓글 표시
if i have this simple equation x=y-2 and I already know the value of y ,(y=scalar), how can i substitute in the above equation and get the value of x?? thx in advance
댓글 수: 0
채택된 답변
Walter Roberson
2011년 12월 20일
solve( subs( sym('x=y-2'), 'y', TheYValue), 'x')
Yes, this is a bit longer than what you might expect. If you were to use
subs( sym('x=y-2'), 'y', TheYValue )
then you would get something of the form
x = SomeValue
with SomeValue possibly being an expression that could be resolved further, as subs() does not evaluate the expression or try to simplify it after the substitution is done, and subs() will leave the expression in the form of an equation rather than trying to isolate x. For example if the expression was 5*x^2 = y - 2 then subs() would just leave it as 5*x^2 = SomeValue .
댓글 수: 3
Walter Roberson
2011년 12월 20일
If the x is already known to be isolated, then
simplify( subs( sym('y-2'), 'y', TheYValue )
should give the reduced value with the expression evaluated after the substitution.
Either way, with solve() or simplify(), once you are down to a single symbolic expression involving no unknowns, you can use double() to convert the symbolic expression to MATLAB double precision.
Image Analyst
2011년 12월 21일
Yes, Walter is a dear. We see "my dear" so often that I'm convinced that it must be something taught (incorrectly) in English language classes - that English-speaking people like to be called "my dear". Sometimes the 70 year old lady serving food at the cafeteria might say that, but not another engineer who'd probably more likely say "You're awesome Walter!".
추가 답변 (1개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!