Why do I get an error when I try to define a symbolic matrix over the Real domain in MUPAD?

조회 수: 2 (최근 30일)
I get an error when I am trying to declare a symbolic matrix of type real in Mupad. There is no error when the matrix contains only numbers.
Specifically, in Mupad using the command:
C := Dom::Matrix(Dom::Real)( [[1, 2, 3], [4, 5, 6], [7, 8, 9]])
which contains only numbers works as expected, however when the matrix elements are defined as symbols, it throws an error:
assume([a, b,c], Type::Real)
A := Dom::Matrix(Dom::Real)( [[1, a, c], [a, 1, b], [c, b, 1]])
and I receive the following warning:
Error: unable to define matrix over Dom::Real [(Dom::Matrix(Dom::Real))::new]
If I replace the (Dom::Real) with (Dom::ExpressionField()) in the symbolic matrix definition, I do not get an error.

채택된 답변

MathWorks Support Team
MathWorks Support Team 2013년 2월 1일
The issue that you are facing is because when the matrix domain constructor 'Dom::Matrix(Dom::Real)' is called , then any of the matrix components must be converted to 'Dom::Real'. So the issue is related to the properties of each element of the matrix and not the properties of the complete matrix.
The help page for 'Dom::Real' says that when using 'Dom::Real(x)' then 'x' needs to be an expression of type DOM_INT, DOM_RAT or DOM_FLOAT. An expression of type DOM_EXPR is also allowed if it is of type Type::Arithmetical and if it contains indeterminates which are only of type Type::ConstantIdents (like PI etc) with no imaginary part. When using the symbolic matrix the the symbolic elements are internally not implemented as Real but as complex variables. The results can be simplified in the end and be displayed according to the assumptions using the command SIMPLIFY.
Similarly we would still get an error if we were to do the following:
>>assume(a, Type::Real)
>>Dom::Real(a)
Error: illegal arguments [Dom::Real::new]
To define a matrix with real components containing symbols, one option is to first set the assumptions on the symbolic identifiers in the matrix as:
assume([a, b,c], Type::Real)
A := matrix( [[1, a, c], [a, 1, b], [c, b, 1]])
Alternatively, define the matrix regularly then apply the assumption to each element, e.g.:
a := matrix(2,2);
a[1,1]:=a_1_1;
a[1,2]:=a_1_2;
a[2,1]:=a_2_1;
a[2,2]:=a_2_2;
Then use either:
for X in a do assumeAlso(X in R_) end
or:
map([op(a)], assumeAlso, Type::Real)
Also be aware with these:
1) Any assumption overwrites all previous assumptions on the same identifier. Thus,
map([op(a)], assume, Type::Real)
is possible in somce cases but could lead to unwanted results if the same identifier occurs in several matrix entries.
2) An assumption ends when the current function is left. Thus using a local function
map([op(a)], X -> assume(X in R_))
would NOT be what you want.

추가 답변 (0개)

태그

아직 태그를 입력하지 않았습니다.

제품


릴리스

R2009a

Community Treasure Hunt

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

Start Hunting!

Translated by