making a substitution
10 次查看(过去 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!