Passing the numeric matrix to symbolic function

조회 수: 2 (최근 30일)
Vishakha Ramani
Vishakha Ramani 2018년 2월 14일
댓글: Vishakha Ramani 2018년 2월 14일
Hello,
I have created a function containing symbolic expressions. The expressions make use of a symbolic matrix. I want to solve the function passing the numeric matrix which replaces the symbolic matrix and provides a numeric answer. I can't seem to understand how to pass the numeric matrix.
function example
R= sym('R',[3 3])
r_b= R([1 2], [3])
R_bar= R([1 2], [1 2])
R_til=R([2 3],[2 3])
syms alpha_bar beta_bar
a_bar= [1;alpha_bar]
b_bar= [beta_bar;1]
P= sym(R_bar*a_bar)
Q= sym(R_til*b_bar)
syms E_a E_b
u_bar= [1; 0]
v_bar= [0;1]
W = sym(E_a*u_bar)
X= sym(E_b*v_bar)
C= sym(P==W)
D= sym(Q==X)
[alpha_bar_, E_a_] = solve(P==W,[alpha_bar,E_a])
[beta_bar_, E_b_] = solve(Q==X,[beta_bar,E_b])
a_bar= [1;alpha_bar_]
b_bar=[beta_bar_;1]
delta= (a_bar)'*r_b
gamma_b = delta/E_b_
gamma_a= delta/E_a_
a= [a_bar;0]-(gamma_b*[0;b_bar])
b= [0;b_bar]-gamma_a*[a_bar;0]
end
My R is R= [1 1 0; 1 3 2; 0 2 3].
Any help on this example would be deeply appreciated.
Thank You.

채택된 답변

Karan Gill
Karan Gill 2018년 2월 14일
You're not passing any arguments to the function. To learn that, see function.
If you want a numerical result, instead of a symbolic solver like solve, use a numeric solver like vpasolve or fsolve.
Lastly, any numeric input can be converted to symbolic form by using sym(input).
  댓글 수: 2
Vishakha Ramani
Vishakha Ramani 2018년 2월 14일
I read the link provided by you and converted numeric input to symbolic form. The solution worked. Thank you very much.
Karan Gill
Karan Gill 2018년 2월 14일
Glad to hear that!

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2018년 2월 14일
subs(a, R, NumericR)
and you might want to double() the results.
You need to avoid assigning a numeric value to R itself for this to work.
  댓글 수: 1
Vishakha Ramani
Vishakha Ramani 2018년 2월 14일
I wanted to pass the numeric matrix from the command window. I passed the appropriate arguments to the function and it worked. Thank you so very much for the help.

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by