# How to create a matrix with variables?

1. Jan 28, 2016

### influx

Hello,

I am kind of new to Matlab so the questions I will ask probably sound a bit basic. Anyways, here goes:

I want to create the matrix below which has both constants and variables. How can I do this? I know how to create a normal matrix (e.g. B = [1 0 2; 3 4 5; 0 2 3]) but I don't know how to create matrices with variables in them?

I tried to type the matrix in as is shown above but it doesn't seem to work. I'm pretty sure I should be following some sort of method but I have no clue.

Apart from element a31, all the elements are constants that I've been given (Fc, Vc, Vr, Fr and dt are constants). Element a31 can vary since the ''Act'' term can vary. I understand that I can just enter the constants instead for the other elements, but for now I'd like to enter the elements so it looks like the image I posted.

EDIT: I'd like to add that in element a44, there should be no ''/'' sign. That is a mistake. It should be just 1-Fc*dt/Vc.

Thanks!

2. Jan 28, 2016

### johnnyTransform

I'm not entirely sure that you can use symbolic variables in a MATLAB matrix like that. If the variable act changes value over time, I'd create a loop with the number of time steps desired and calculate the value of act during each iteration, and then in that same iteration manually update the matrix with the new value.

e.g.

Code (Text):
act = ...;
%Value of act at t=0.

%...Now initialize the matrix....%

matrix(3,1)=act*fr*dt/vr;
%Substitute the correct value into the (3,1) slot of the matrix%

for j=1:1:numberOfTimeSteps

act=....;
%Value of act at time step j.
matrix(3,1)=act*fr*dt/vr;

%....matrix calculations....%

end

3. Jan 30, 2016

### influx

Act doesn't vary over time.

To clarify, the problem is as follows:

X(t) = AX(t-1)

Where X(t) is a column vector consisting of elements X1(t), X2(t), X3(t) and X4(t). Matrix A is the matrix in the image above and X(t-1) is a column vector consisting of elements X1(t-1), X2(t-1), X3(t-1) and X4(t-1).

So the multiplication of matrix A (in the image above) with X(t-1) yields us X(t) [which is the value that comes after X(t-1)]. Essentially, matrix A is used to help yield a prediction of the next state [X(t)] and this will then be compared to the actual next state obtained via measurement.

The value of Act (which represents activity) depends on the subject tested. For each subject (i.e individual) tested, I have an Excel file with the results of their tests and the value for Act for each subject is within this excel file.

So for each subject, I need to multiply matrix A with column vector X(t-1) but as I explained, each subject will have had a different Act.

I want to write the matrix A exactly as in the picture, then have the ability to assign values to Act and the other elements (the other elements will be assigned constant values for all subjects but Act will vary depending on the subject). I am not sure if it is possible to create a loop to (by selecting the excel files?) or whether I have to manually assign the value of Act each time?

I hope that clarifies it!

Last edited: Jan 30, 2016
4. Feb 2, 2016