필터 지우기
필터 지우기

Indexing inside symbolic product

조회 수: 27 (최근 30일)
Aaron J. Hendrickson
Aaron J. Hendrickson 2017년 7월 25일
댓글: Aaron J. Hendrickson 2017년 7월 25일
I am trying to compute a symbolic product with the following code:
syms z theta_1 theta_2 k real
n = 2;
x = sym('x', [n 1])
assumeAlso(theta_2>0)
f = symfun(exp(-(z-theta_1)^2/(2*theta_2))/sqrt(2*pi*theta_2),[z, theta_1, theta_2])
L = symprod(f(x(k),theta_1,theta_2),k,1,n)
However, when I run the code I get the following error:
Error using sym/subsindex (line 766)
Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.
Error in sym/subsref (line 805)
R_tilde = builtin('subsref',L_tilde,Idx);
Could someone please explain what is going wrong here? Been staring at this for way to long.

채택된 답변

Walter Roberson
Walter Roberson 2017년 7월 25일
Syms can never be used as indices.
Construct a vector of the individual values (sometimes this is very easy if only happen to use vectorizable operations), and then prod() the vector
  댓글 수: 1
Aaron J. Hendrickson
Aaron J. Hendrickson 2017년 7월 25일
That works. Thank you.
L = prod(f(x,theta_1,theta_2))

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by