(Good Ol') Error in MuPAD command: DOUBLE cannot convert...

I know many a question like this has been asked before, but the cases that I've seen are more complicated and the answers appear to pertain only to the specific cases.
My case is very simple (and therefore broadly applicable), taken from MATLAB's very own help page:
syms x
f(x) = [x x^2; x^3 x^4];
f(2)
The output is supposed to be as follows, but instead I get the error message. How come? And how do I fix it? Thanks.
ans =
[ 2, 4]
[ 8, 16]

4 Comments

I get an error when I copy your code into "one" line in the command line...
>> syms x
f(x) = [x x^2; x^3 x^4];
f(2)
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.
When I go line for line...
>> clear all
>> syms x
>> f(x) = [x x^2; x^3 x^4];
>> f(2)
ans =
[ 2, 4]
[ 8, 16]
No idea why??
f already existed as a numeric array. f(x) then fails to convert the symbol x to an array of numbers to use as indices into f.
@WR Could you elaborate, please? I don't quite understand, but of course the number in the parentheses is meant to be an argument, not an index. If that's the problem, then how do I accomplish what I'm trying to do? Thanks.
Which MATLAB version are you using? The ability to define a function with that syntax is relatively new. Before that, the conversion to double error would occur while trying to create an index, and that would not depend on whether f already existed or not.

Sign in to comment.

Answers (0)

Products

Tags

Asked:

on 12 Nov 2013

Commented:

on 12 Nov 2013

Community Treasure Hunt

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

Start Hunting!