How do I set a parameter in a symbolic expression?
4 次查看(过去 30 天)
显示 更早的评论
Dear Matlab Community,
I got a problem on how to set a parameter in my program. I solved some equations and the solution is a symbolic equation. This solution is correct. To keep it easy in this question: let the solution be like this:
syms a b
...%here are some equations that solve for a
...%this is the symbolic solution:
a = 3*b
Now I want to set b = 2 for example and wish to get the value for a. It should be a = 6 in that case. How can I set b = 2 and get the solution for a after getting the symbolic solution.
I tried:
a2 = solve(b == 2,a)
but it did not work. I hope someone could help me solving this maybe easy problem, then I can apply it to my original code which is a little more complicated. So I need to set b after solving symbolic for a.
Thank you! Stefan
0 个评论
回答(2 个)
Mischa Kim
2015-2-11
编辑:Mischa Kim
2015-2-11
Stefan, use
syms a(b)
a = 3*b;
a2 = subs(a,b,2)
2 个评论
Mischa Kim
2015-2-11
Use the double command, see the example below.
syms y(x)
y = x^(1/2)
a1 = subs(y,x,2)
a1 =
2^(1/2)
a2 = double(subs(y,x,2))
1.4142
Stefan Henning
2015-2-11
1 个评论
Mischa Kim
2015-2-11
Please add follow-up comments and questions as comments, not as answers. I have answered your question above.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!