Creating multiple symbolic functions with arguments
Show older comments
I can use
x = sym('x',[n,1]);
y = sym('y',[n,1]);
to create symbolic variables of length 'n'.
I would like to create symbolic functions x(t) and y(t) of the same length. But the above syntax doesn't accept an argument.
x = sym('x(t)',[n,1]);
y = sym('y(t)',[n,1]);
gives an error 'If the second argument specifies the dimensions of the generated symbolic vector or matrix, then the first argument must be a character vector specifying the base name for vector or matrix elements. It must be a valid variable name.'
The only way to create them seems to be
syms x(t) y(t)
But I need them to be of length 'n'. The rest of my code depends on the value of 'n'. It contains odes which consist of diff(x(i),t) and diff(y(i),t), where 'i' would vary from 1 to 'n'. How can I define x(t) and y(t) of length 'n'?
What I desire in the end is this:
Suppose n=3. If I knew this, then I would do
syms x1(t) x2(t) x3(t) y1(t) y2(t) y3(t)
Here, I have created a total of 6 functions. Then, if I have some polynomial
p = x1^3 + 5y2 + 4x2^4 + y3^2
I would be able to write an ode of the form
ode1 = diff(x1,t) == p
ode2 = diff(x2,t) == p
But I don't know 'n'. I would like to create a code which creates the corresponding functions in a loop, once I know 'n'. So, if I put n=4, I should immediately get 8 functions: x1,x2,x3,x4,y1,y2,y3,y4, all functions of 't'. How do I do this?
Accepted Answer
More Answers (0)
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!