|
Hi,
I am new to Matlab so please bear with me. I have two questions that you may be able to help with:
1. Firstly, I would like to enter a 5-element vector, X, consisting of symbolic elements. The symbolic elements will eventually be substituted with positive real values, later on in the code. I know that I can enter such a symbolic vector as follows:
>> sym('x1','positive');
For x1 to x5. Then
>> X = [x1 x2 x3 x4 x5]'
X =
x1
x2
x3
x4
x5
This works fine, but I am wondering why I cannot use the method given in Matlab help, which states "To create a symbolic vector or a symbolic matrix A, use A = sym('A', [m n]) or A = sym('A', n).". When I do this, I get the following error:
>> X=sym('X',[5 1])
??? Error using ==> error
Formatted arguments cannot be non-scalar numeric matrices.
Error in ==> sym.sym>assumptions at 2180
error('symbolic:sym:sym:errmsg1','Second argument %s not
recognized.',a);
Error in ==> sym.sym>tomupad at 2148
assumptions(S,x,a);
Error in ==> sym.sym>sym.sym at 114
S.s = tomupad(x,a);
I am not sure where I am going wrong.
2. Secondly, I need to create symbolic sums. As a simple example, I would like Matlab to assign to variable S the sum from i=1 to 5, of X(i)*log(X(i)), where X(i) refers to element i of vector X. I know I can explicitly enter the whole formula. However, the sums get considerably more complicated (including sums of sums) and thus I would prefer not to have to enter every term. I don't know why the following doesn't work:
>> syms i
>> S = symsum(X(i)*log(X(i)),i,1,5)
??? Error using ==> mupadmex
Error in MuPAD command: DOUBLE cannot convert the input expression into a
double array.
If the input expression contains a symbolic variable, use the VPA function
instead.
Error in ==> sym.sym>sym.double at 927
Xstr = mupadmex('mllib::double', S.s, 0);
Error in ==> sym.sym>privformatscalar at 2539
x = double(x);
Error in ==> sym.sym>privformat at 2524
s = privformatscalar(x);
Error in ==> sym.sym>sym.subsref at 1364
[inds{k},refs{k}] = privformat(inds{k});
Your help in solving these two problems would be greatly appreciated.
Thanks in advance,
Dean
|