How to write a symbolic variable funtion?

I followed the instruction for symbolic variables in this link: http://www.mathworks.com.au/help/symbolic/syms.html
But it gives me error instead a function with symbolic variable. Someone please help me! Thanks!
>> clear all
>> syms f(x, y)
Error using syms (line 61)
Not a valid variable name.
>> syms x
>> f(x) = [x x^2; x^3 x^4];
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/double (line 936)
Xstr = mupadmex('symobj::double', S.s, 0);
Error in sym>privformatscalar (line 2707)
x = double(x);
Error in sym>privformat (line 2692)
s = privformatscalar(x);
Error in sym/subsasgn (line 1462)
[inds{k},refs{k}] = privformat(inds{k});
>>

 채택된 답변

Youssef  Khmou
Youssef Khmou 2013년 5월 6일
편집: Youssef Khmou 2013년 5월 6일

0 개 추천

hi,
No the notation f(x) is used in other programming languages ,try :
syms x
f=[x x^2;x^3 x^4]
% automatically f is f(x)
here is second example :
syms x y
F=[cos(x) sin(y); -sin(y) cos(x)];

댓글 수: 4

Aggie W
Aggie W 2013년 5월 6일
Im glad to hear your response But I need two variables in f which make it f(x y) and later on I want to substitute values of x and y into f function
Youssef  Khmou
Youssef Khmou 2013년 5월 6일
ok, i edited the answer
Aggie W
Aggie W 2013년 5월 6일
편집: Aggie W 2013년 5월 6일
What do I then obtain a matrix of f if x=complex(1,5) and y=complex(8,4)?
Youssef  Khmou
Youssef Khmou 2013년 5월 6일
편집: Youssef Khmou 2013년 5월 6일
i think the variables must have the same size :
syms x y
F=[cos(x) sin(y); -sin(y) cos(x)];
X=exp(j*(0:5));
Y=exp(5*j*(0:5));
H=subs(F,{x,y},{X,Y})
I can not tell if they dont have the same size

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

추가 답변 (1개)

Walter Roberson
Walter Roberson 2013년 5월 6일

1 개 추천

The notation syms f(x, y) is relatively new; R2011b I think it was (might be R2012a). Try this:
f = evalin(symengine, '(x,y) -> [x, x^2, x^3, x^4]')
Note: this will not produce the 2 x 2 array you were looking for, but if it produces a "proc" output then you could work on forming the proper array form at that time (once proof of concept has been worked out)

Community Treasure Hunt

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

Start Hunting!

Translated by