I want to define a symbolic vector in Matlab, but every element of the vector should be created through a symbolic function.
Let's say f(x)=x^2 is my function and I have a vector A=[1 2 3 4 5]. I want to create a symbolic vector so that it is going to be like this;
Symbolic_vector=[x^2 2*x^2 3*x^2 4*x^2 5*x^2]
How can I realize this ?
So far I have
A=[1 2 3 4 5];
syms x;
m = sym('m', [1 100]);
f = sym('x^2*m');
f = subs(f, m, A);
One way to do this and keep things symbolic is
A = sym('[1 2 3 a 5]');
f = @(x) x.^2;
B = f(A);
% results in B = [1 4 9 a^2 25]
You can also do directly
B = A.^2;
syms a;
A = [1 2 3 a 5];
B = A.^2;
I hope this helps.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.