Prev: Simulink Waveform Viewing Help
Next: oqpsk code
From: ecksor ansari on 23 May 2010 13:26 i have below program for matrix multiplication: [m,n]=size(a); [k,l]=size(b); c=zeros(m,l); for i=1:m, for j=1:l, for p=1:n, c(i,j)=c(i,j)+a(i,p)*b(p,j); end end end i need to define a and b as a(x) and b(x), but then matlab returns this error: --------------------------------------------------------------------------------- ??? The following error occurred converting from sym to double: 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. --------------------------------------------------------------------------------- how can i change it to symbolic form?
From: Walter Roberson on 23 May 2010 14:13 ecksor ansari wrote: > i have below program for matrix multiplication: > [m,n]=size(a); > [k,l]=size(b); > c=zeros(m,l); > for i=1:m, > for j=1:l, > for p=1:n, > c(i,j)=c(i,j)+a(i,p)*b(p,j); > end > end > end > > i need to define a and b as a(x) and b(x), but then matlab returns this > error: > --------------------------------------------------------------------------------- > > ??? The following error occurred converting from sym to double: > Error using ==> mupadmex > Error in MuPAD command: DOUBLE cannot convert the input expression > into a double array. Which line does it report that for? It is not possible to receive that error unless there are key lines that you have not shown us, such as declarations of something as a symbolic variable. > how can i change it to symbolic form? You cannot code a symbolic multiplication with a 'for' loop: 'for' requires numeric values to iterate over. If you want to code a symbolic matrix multiplication, use the symbolic toolbox's matrix multiplication. Watch out for rank problems. You mention defining "a" as a(x) but that implies a vector and you are using it as a matrix with two subscripts. If you happen to be multiplying two vectors together, remember that matrix multiplication cannot do that unless one of the two is a row vector and the other is a column vector of the same length. You should be doing error checking to be sure the matrices are the correct relative shape -- that n == k. It is not recommended to use lower-case-L (l) as a variable name, as it is too easy to misread it as the digit one (1). Indeed with the font I am using right now, there is no visible difference.
From: Steven Lord on 24 May 2010 09:42 "ecksor ansari" <vvahidd(a)gmail.com> wrote in message news:htbofc$dme$1(a)fred.mathworks.com... >i have below program for matrix multiplication: > [m,n]=size(a); > [k,l]=size(b); > c=zeros(m,l); > for i=1:m, > for j=1:l, > for p=1:n, > c(i,j)=c(i,j)+a(i,p)*b(p,j); > end > end > end > > i need to define a and b as a(x) and b(x), but then matlab returns this > error: > --------------------------------------------------------------------------------- > ??? The following error occurred converting from sym to double: > 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. > --------------------------------------------------------------------------------- > > how can i change it to symbolic form? As you've defined c above, it's a double array. When you compute a(i, p)*b(p, j) [assuming one or both of those matrices contain a symbolic variable] the result is a sym object. Adding that sym object to a double [c(i, j)] results in another sym object. In order to assign that sym object into a double array, MATLAB would need to convert the sym object into a double array using the DOUBLE function. Because the sym object contains a symbolic variable, however, it cannot. Either define c to be a sym object: c = sym(zeros(m, l)); or just compute the product of a and b directly. c = a*b; -- Steve Lord slord(a)mathworks.com comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ To contact Technical Support use the Contact Us link on http://www.mathworks.com
|
Pages: 1 Prev: Simulink Waveform Viewing Help Next: oqpsk code |