필터 지우기
필터 지우기

How do I set a parameter in a symbolic expression?

조회 수: 4 (최근 30일)
Stefan Henning
Stefan Henning 2015년 2월 11일
댓글: Stefan Henning 2015년 2월 11일
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

답변 (2개)

Mischa Kim
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
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
Stefan Henning 2015년 2월 11일
thanks a lot! this works fine

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


Stefan Henning
Stefan Henning 2015년 2월 11일
Thanks a lot! Now I get a solution. But one more thing: The value of my specific case has some form like this:
y = -1000/(300*3^(1/2)-100)
How do I get just one value and not an expression? In this case I would like to get
y = -2.383135547
Thank you!
  댓글 수: 1
Mischa Kim
Mischa Kim 2015년 2월 11일
Please add follow-up comments and questions as comments, not as answers. I have answered your question above.

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

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by