MATLAB: How to make a mtrix of N symbolic variables dependant on ‘t’

differential equationsMATLABsymbolic

I need to make a system of N differential equations with N functions dependant on symbolic matht or other variable + Border Conditions. and solve it.
What I tried to do:
% dimension. in principle N can be any big
N = 3;
% matrix of coefficients. here I set it manually for simplicity
a = [1, 2, 3; 4, 5, 6; 7, 8, 9];
% make a set of N variables
b = sym('x_%d', [N, 1]);
for i = 1 : N
eqns(i) = sum(a(i, :) * b(:)) == diff(b(i));
But as far as I do not use syms manually like that:
syms t x_1(t) x_2(t) x_3(t)
MatLab doesn't know that my variable should depend on t and therefore diff(b(i)) = 0 always. I don't even know how to set the Border Conditions this way, because MatLab doesn't let me make a matrix of conditions conds, where I could index the number of condition and set t = 0 at the same time.
Is there a solution to this issue?

Best Answer

  • I found solution, don't remember where, but hope it would be useful for others.
    N1 = 5;
    N2 = 5;
    syms t
    for k1 = 0 : N1
    for k2 = 0 : N2
    PSI_t = ['PSI_f_' num2str(k1 + 1) '_' num2str(k2 + 1) '(t_ent1)'];
    PSI(k1 + 1, k2 + 1) = symfun(PSI_t, t);
    First, we need to make a name of the symbolic function which we can address and which includes the matrix indexes. After that we make it being a function of other variables as an element of another matrix.
    Now we can address the symbolic functions as PSI(1, 2) and use it in equations. As for the initial conditions or other stuff, we can use subs:
    example_condition = subs(PSI(1, 1), t, 0) == 1;